@@ -46,8 +46,10 @@ const withAttributeBinder = createHigherOrderComponent( ( BlockEdit ) => {
46
46
'meta'
47
47
) ;
48
48
49
- // Saving the fields as serialized JSON because I was tired of fighting the REST API.
50
- const fields = meta ?. fields ? JSON . parse ( meta . fields ) : [ ] ;
49
+ const fields = useMemo ( ( ) => {
50
+ // Saving the fields as serialized JSON because I was tired of fighting the REST API.
51
+ return meta ?. fields ? JSON . parse ( meta . fields ) : [ ] ;
52
+ } , [ meta . fields ] ) ;
51
53
52
54
const { attributes, setAttributes, name } = props ;
53
55
@@ -81,7 +83,7 @@ const withAttributeBinder = createHigherOrderComponent( ( BlockEdit ) => {
81
83
} ) ;
82
84
83
85
setAttributes ( newAttributes ) ;
84
- } , [ attributes . metadata , setAttributes ] ) ;
86
+ } , [ attributes . metadata , setAttributes , fields , setMeta ] ) ;
85
87
86
88
const selectedBlockType = getBlockType ( name ) ;
87
89
@@ -196,43 +198,40 @@ const withAttributeBinder = createHigherOrderComponent( ( BlockEdit ) => {
196
198
return < BlockEdit { ...props } /> ;
197
199
}
198
200
201
+ const bindings = attributes ?. metadata ?. [ window . BINDINGS_KEY ] ;
202
+
199
203
return (
200
204
< >
201
205
< InspectorControls >
202
206
< PanelBody title = "Attribute Bindings" initialOpen >
203
- { ! editingBoundAttribute &&
204
- attributes ?. metadata ?. [
205
- window . BLOCK_VARIATION_NAME_ATTR
206
- ] && (
207
- < ItemGroup isBordered isSeparated >
208
- { supportedAttributes . map (
209
- ( attribute ) => (
210
- < Item key = { attribute } >
211
- < Flex >
212
- < FlexBlock >
213
- { attribute }
214
- </ FlexBlock >
207
+ { ! editingBoundAttribute && bindings && (
208
+ < ItemGroup isBordered isSeparated >
209
+ { supportedAttributes . map ( ( attribute ) => {
210
+ return (
211
+ < Item key = { attribute } >
212
+ < Flex >
213
+ < FlexBlock >
214
+ { attribute }
215
+ </ FlexBlock >
216
+ { bindings [ attribute ] && (
215
217
< FlexItem >
216
218
< span >
217
219
< code >
218
220
{
219
- attributes
220
- ?. metadata ?. [
221
- window
222
- . BINDINGS_KEY
223
- ] [
221
+ bindings [
224
222
attribute
225
223
]
226
224
}
227
225
</ code >
228
226
</ span >
229
227
</ FlexItem >
230
- </ Flex >
231
- </ Item >
232
- )
233
- ) }
234
- </ ItemGroup >
235
- ) }
228
+ ) }
229
+ </ Flex >
230
+ </ Item >
231
+ ) ;
232
+ } ) }
233
+ </ ItemGroup >
234
+ ) }
236
235
{ ! editingBoundAttribute && (
237
236
< PanelRow >
238
237
< ButtonGroup >
@@ -246,9 +245,7 @@ const withAttributeBinder = createHigherOrderComponent( ( BlockEdit ) => {
246
245
>
247
246
{ __ ( 'Manage Binding' ) }
248
247
</ Button >
249
- { attributes ?. metadata ?. [
250
- window . BLOCK_VARIATION_NAME_ATTR
251
- ] && (
248
+ { bindings && (
252
249
< Button
253
250
isDestructive
254
251
onClick = { removeBindings }
0 commit comments