Skip to content

Commit

Permalink
sync derevied updates when updating bound attr
Browse files Browse the repository at this point in the history
  • Loading branch information
retrofox committed Feb 22, 2024
1 parent 142d0e7 commit 52c04f3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/block-editor/src/hooks/use-bindings-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { getBlockType } from '@wordpress/blocks';
import { createHigherOrderComponent } from '@wordpress/compose';
import { useSelect } from '@wordpress/data';
import { useSelect, useDispatch } from '@wordpress/data';
import { useEffect, useCallback } from '@wordpress/element';
import { addFilter } from '@wordpress/hooks';
import { RichTextData } from '@wordpress/rich-text';
Expand Down Expand Up @@ -85,6 +85,8 @@ const BindingConnector = ( {

const setAttributes = blockProps.setAttributes;

const { syncDerivedUpdates } = unlock( useDispatch( blockEditorStore ) );

const updateBoundAttibute = useCallback(
( newAttrValue, prevAttrValue ) => {
/*
Expand All @@ -99,11 +101,13 @@ const BindingConnector = ( {
prevAttrValue = prevAttrValue.toHTMLString();
}

setAttributes( {
[ attrName ]: newAttrValue,
syncDerivedUpdates( () => {
setAttributes( {
[ attrName ]: newAttrValue,
} );
} );
},
[ attrName, setAttributes ]
[ attrName, setAttributes, syncDerivedUpdates ]
);

useEffect( () => {
Expand Down

0 comments on commit 52c04f3

Please sign in to comment.