Skip to content

Commit

Permalink
Don't update non-bound attributes when using patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
SantosGuillamot committed May 7, 2024
1 parent 1e7060e commit d823ba8
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/block-editor/src/hooks/use-bindings-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { addFilter } from '@wordpress/hooks';
* Internal dependencies
*/
import { unlock } from '../lock-unlock';
import { store as blockEditorStore } from '../store';

/** @typedef {import('@wordpress/compose').WPHigherOrderComponent} WPHigherOrderComponent */
/** @typedef {import('@wordpress/blocks').WPBlockSettings} WPBlockSettings */
Expand Down Expand Up @@ -124,9 +125,18 @@ export const withBlockBindingSupport = createHigherOrderComponent(
binding.source === 'core/pattern-overrides'
)
) {
for ( const attributeName in nextAttributes ) {
if ( ! bindings[ attributeName ] ) {
delete keptAttributes[ attributeName ];
// Don't update non-bound attribute only when using the pattern and not when editing the original one.
const { getBlockParents, getBlockName } =
registry.select( blockEditorStore );
const parents = getBlockParents( clientId, true );
const patternClientId = parents.find(
( id ) => getBlockName( id ) === 'core/block'
);
if ( patternClientId ) {
for ( const attributeName in nextAttributes ) {
if ( ! bindings[ attributeName ] ) {
delete keptAttributes[ attributeName ];
}
}
}
}
Expand Down

0 comments on commit d823ba8

Please sign in to comment.