Skip to content

Commit a6e46ad

Browse files
Widget Editor: Fix allow adding same image twice (#32951)
* Widget Editor: Fix allow adding same image twice * remove duplicate reference widget instances only for legacy widgets * update id check Co-authored-by: Kai Hao <[email protected]> Co-authored-by: Kai Hao <[email protected]>
1 parent 12df6f9 commit a6e46ad

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

packages/edit-widgets/src/store/actions.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,15 @@ export function* saveWidgetArea( widgetAreaId ) {
108108
( { sidebar } ) => sidebar === widgetAreaId
109109
);
110110

111-
// Remove all duplicate reference widget instances
111+
// Remove all duplicate reference widget instances for legacy widgets.
112+
// Why? We filter out the widgets with duplicate IDs to prevent adding more than one instance of a widget
113+
// implemented using a function. WordPress doesn't support having more than one instance of these, if you try to
114+
// save multiple instances of these in different sidebars you will run into undefined behaviors.
112115
const usedReferenceWidgets = [];
113-
const widgetsBlocks = post.blocks.filter( ( { attributes: { id } } ) => {
114-
if ( id ) {
116+
const widgetsBlocks = post.blocks.filter( ( block ) => {
117+
const { id } = block.attributes;
118+
119+
if ( block.name === 'core/legacy-widget' && id ) {
115120
if ( usedReferenceWidgets.includes( id ) ) {
116121
return false;
117122
}

0 commit comments

Comments
 (0)