From 5d5bbdbcda1e1e1f8498de94c49179639c6e96f7 Mon Sep 17 00:00:00 2001 From: Michal Czaplinski Date: Wed, 14 Feb 2024 11:26:51 +0000 Subject: [PATCH] Fix initial value assignment in BlockBindingConnector --- .../with-block-binding-support.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/block-editor/src/components/block-binding-support/with-block-binding-support.js b/packages/block-editor/src/components/block-binding-support/with-block-binding-support.js index c332eee0288e5d..620d502309f092 100644 --- a/packages/block-editor/src/components/block-binding-support/with-block-binding-support.js +++ b/packages/block-editor/src/components/block-binding-support/with-block-binding-support.js @@ -34,9 +34,9 @@ const BlockBindingConnector = ( { blockProps, args, } ) => { - const lastPropValue = useRef(); - const lastAttrValue = useRef(); const { value, updateValue } = useSource( blockProps, args ); + const lastPropValue = useRef( value ); + const lastAttrValue = useRef( attrValue ); const setAttributes = blockProps.setAttributes; @@ -49,6 +49,13 @@ const BlockBindingConnector = ( { [ attrName, setAttributes ] ); + /* Set the initial value of the block attribute */ + useEffect( () => { + setAttributes( { + [ attrName ]: value, + } ); + }, [] ); + /* * Source Prop => Block Attribute *