File tree Expand file tree Collapse file tree 4 files changed +73
-7
lines changed
library/panes/media/common Expand file tree Collapse file tree 4 files changed +73
-7
lines changed Original file line number Diff line number Diff line change 2020import styled , { css } from 'styled-components' ;
2121import { Blurhash } from 'react-blurhash' ;
2222
23+ /**
24+ * Internal dependencies
25+ */
26+ import { HideOnError } from '../hideOnError' ;
27+
2328const placeholderStyles = css `
2429 position: absolute !important;
2530 top: 0;
@@ -40,7 +45,14 @@ const BaseColorContainer = styled.div`
4045function renderResourcePlaceholder ( { blurHash, baseColor } ) {
4146 if ( blurHash ) {
4247 return (
43- < BlurhashContainer hash = { blurHash } punch = { 1 } height = "100%" width = "100%" />
48+ < HideOnError >
49+ < BlurhashContainer
50+ hash = { blurHash }
51+ punch = { 1 }
52+ height = "100%"
53+ width = "100%"
54+ />
55+ </ HideOnError >
4456 ) ;
4557 }
4658
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2024 Google LLC
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * https://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ /**
18+ * External dependencies
19+ */
20+ import type { PropsWithChildren } from 'react' ;
21+ import { Component } from '@googleforcreators/react' ;
22+
23+ interface HideOnErrorState {
24+ error : Error | null ;
25+ }
26+
27+ export class HideOnError extends Component < PropsWithChildren < unknown > > {
28+ state : HideOnErrorState ;
29+
30+ constructor ( props : PropsWithChildren < unknown > ) {
31+ super ( props ) ;
32+
33+ this . state = {
34+ error : null ,
35+ } ;
36+ }
37+
38+ static getDerivedStateFromError ( error : Error ) {
39+ return { error } ;
40+ }
41+
42+ render ( ) {
43+ const { error } = this . state ;
44+ if ( ! error ) {
45+ return this . props . children ;
46+ }
47+
48+ return null ;
49+ }
50+ }
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ import DropDownMenu from '../local/dropDownMenu';
3838import { ContentType , useLocalMedia } from '../../../../../app/media' ;
3939import Tooltip from '../../../../tooltip' ;
4040import { noop } from '../../../../../utils/noop' ;
41+ import { HideOnError } from '../../../../hideOnError' ;
4142import Attribution from './attribution' ;
4243import InnerElement from './innerElement' ;
4344import InsertionMenu from './insertionMenu' ;
@@ -211,12 +212,14 @@ function Element({
211212 />
212213 { attribution }
213214 { isPlaceholder && blurHash && (
214- < BlurhashContainer
215- hash = { blurHash }
216- width = { width }
217- height = { height }
218- punch = { 1 }
219- />
215+ < HideOnError >
216+ < BlurhashContainer
217+ hash = { blurHash }
218+ width = { width }
219+ height = { height }
220+ punch = { 1 }
221+ />
222+ </ HideOnError >
220223 ) }
221224 { ( ! src ||
222225 isCurrentResourceProcessing ( resourceId ) ||
Original file line number Diff line number Diff line change 4747 " src/app/pageDataUrls" ,
4848 " src/app/story" ,
4949 " src/app/taxonomy" ,
50+ " src/components/hideOnError.tsx" ,
5051 " src/components/library/panes/text/textPresets.ts" ,
5152 " src/components/canvas/*.ts" ,
5253 " src/components/canvas/utils/*.ts" ,
You can’t perform that action at this time.
0 commit comments