From a04a8e94e8b93ba60441c6534e21f4c3c26ff1bc Mon Sep 17 00:00:00 2001 From: Kai Hao Date: Wed, 21 Feb 2024 14:54:43 +0800 Subject: [PATCH] Fix resetting individual blocks to empty values for Pattern Overrides (#59170) Co-authored-by: kevin940726 Co-authored-by: aaronrobertshaw Co-authored-by: talldan --- .../src/components/reset-overrides-control.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/patterns/src/components/reset-overrides-control.js b/packages/patterns/src/components/reset-overrides-control.js index 03d520d2e9b813..586f4608352340 100644 --- a/packages/patterns/src/components/reset-overrides-control.js +++ b/packages/patterns/src/components/reset-overrides-control.js @@ -59,7 +59,19 @@ export default function ResetOverridesControl( props ) { const blocks = editedRecord.blocks ?? parse( editedRecord.content ); const block = recursivelyFindBlockWithId( blocks, id ); - props.setAttributes( block.attributes ); + const newAttributes = Object.assign( + // Reset every existing attribute to undefined. + Object.fromEntries( + Object.keys( props.attributes ).map( ( key ) => [ + key, + undefined, + ] ) + ), + // Then assign the original attributes. + block.attributes + ); + + props.setAttributes( newAttributes ); }; return (