From bde39f78880aefd6fa2b6acb7b7295bad32f2e6b Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Tue, 1 Jun 2021 18:59:49 +1000 Subject: [PATCH] Widgets editor: Fix error when saving empty Legacy Widget block (#32359) --- packages/edit-widgets/src/store/transformers.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/edit-widgets/src/store/transformers.js b/packages/edit-widgets/src/store/transformers.js index 5cebf735efdc07..fb6f1fe546a43c 100644 --- a/packages/edit-widgets/src/store/transformers.js +++ b/packages/edit-widgets/src/store/transformers.js @@ -37,7 +37,11 @@ export function transformWidgetToBlock( widget ) { export function transformBlockToWidget( block, relatedWidget = {} ) { let widget; - if ( block.name === 'core/legacy-widget' ) { + const isValidLegacyWidgetBlock = + block.name === 'core/legacy-widget' && + ( block.attributes.id || block.attributes.instance ); + + if ( isValidLegacyWidgetBlock ) { widget = { ...relatedWidget, id: block.attributes.id ?? relatedWidget.id, @@ -56,13 +60,6 @@ export function transformBlockToWidget( block, relatedWidget = {} ) { }; } - // Delete deprecated properties. - delete widget.description; - delete widget.name; - delete widget.number; - delete widget.settings; - delete widget.widget_class; - // Delete read-only properties. delete widget.rendered; delete widget.rendered_form;