File tree 4 files changed +73
-7
lines changed
library/panes/media/common
4 files changed +73
-7
lines changed Original file line number Diff line number Diff line change 20
20
import styled , { css } from 'styled-components' ;
21
21
import { Blurhash } from 'react-blurhash' ;
22
22
23
+ /**
24
+ * Internal dependencies
25
+ */
26
+ import { HideOnError } from '../hideOnError' ;
27
+
23
28
const placeholderStyles = css `
24
29
position: absolute !important;
25
30
top: 0;
@@ -40,7 +45,14 @@ const BaseColorContainer = styled.div`
40
45
function renderResourcePlaceholder ( { blurHash, baseColor } ) {
41
46
if ( blurHash ) {
42
47
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 >
44
56
) ;
45
57
}
46
58
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';
38
38
import { ContentType , useLocalMedia } from '../../../../../app/media' ;
39
39
import Tooltip from '../../../../tooltip' ;
40
40
import { noop } from '../../../../../utils/noop' ;
41
+ import { HideOnError } from '../../../../hideOnError' ;
41
42
import Attribution from './attribution' ;
42
43
import InnerElement from './innerElement' ;
43
44
import InsertionMenu from './insertionMenu' ;
@@ -211,12 +212,14 @@ function Element({
211
212
/>
212
213
{ attribution }
213
214
{ 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 >
220
223
) }
221
224
{ ( ! src ||
222
225
isCurrentResourceProcessing ( resourceId ) ||
Original file line number Diff line number Diff line change 47
47
" src/app/pageDataUrls" ,
48
48
" src/app/story" ,
49
49
" src/app/taxonomy" ,
50
+ " src/components/hideOnError.tsx" ,
50
51
" src/components/library/panes/text/textPresets.ts" ,
51
52
" src/components/canvas/*.ts" ,
52
53
" src/components/canvas/utils/*.ts" ,
You can’t perform that action at this time.
0 commit comments