gridstack / gridstack.js

Build interactive dashboards in minutes.
https://gridstackjs.com
MIT License
6.53k stars 1.27k forks source link

empty addedNodes and removedNodes before triggering event to prevent infinite loop #2617

Closed galizhur closed 6 months ago

galizhur commented 6 months ago

If you call addWidget inside the grid added or removed events, the items passed in the event for the

Calling addWidget inside the "added" event triggers another "added" event with the items argument containing the newly added item and the initial item that triggered the first added event. The second "added" event should contain only the newly added item.

This happens because the "added" event is triggerd first and the internal addedNodes array is emptied afterwards. The fix was to empty the addedNodes array before triggering the "added" event.

The same happens when calling removeWidget inside the "removed" event.

adumesny commented 6 months ago

would be great if you didn't reformat/pretty the existing code...

galizhur commented 6 months ago

would be great if you didn't reformat/pretty the existing code...

yeah. sorry about that. i didn't notice there were so many reformats :(