Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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]>
  • Loading branch information
2 people authored and youknowriad committed Jun 25, 2021
commit 90a317bfd8e13b03824af6a60639c05b0b4c7e03
11 changes: 8 additions & 3 deletions packages/edit-widgets/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,15 @@ export function* saveWidgetArea( widgetAreaId ) {
( { sidebar } ) => sidebar === widgetAreaId
);

// Remove all duplicate reference widget instances
// Remove all duplicate reference widget instances for legacy widgets.
// Why? We filter out the widgets with duplicate IDs to prevent adding more than one instance of a widget
// implemented using a function. WordPress doesn't support having more than one instance of these, if you try to
// save multiple instances of these in different sidebars you will run into undefined behaviors.
const usedReferenceWidgets = [];
const widgetsBlocks = post.blocks.filter( ( { attributes: { id } } ) => {
if ( id ) {
const widgetsBlocks = post.blocks.filter( ( block ) => {
const { id } = block.attributes;

if ( block.name === 'core/legacy-widget' && id ) {
if ( usedReferenceWidgets.includes( id ) ) {
return false;
}
Expand Down