BUG: Sorter never removes its canvas refresh listener
GrapesJS version
- I confirm to use the latest version of GrapesJS
What browser are you using?
firefox et Chromium 141
Reproducible demo link
https://codepen.io/editor/lexoyo/pen/01a0c4d2-e96f-7d1b-b9eb-6a3475c1fb3a
Describe the bug
The Sorter's constructor registers em.on(Canvas.events.refresh, this.updateOffset) and nothing ever removes it, so every drag through CommandSelectPosition or Droppable leaves a sorter with its container context, including the frame Document
How to reproduce the bug?
- Open the demo, which prints the number of
canvas:refreshlisteners. - Drag a box around the canvas three times.
- Watch the count.
What is the expected behavior?
The count goes back to what it was once a drag is over.
What is the current behavior?
It grows by one per drag and never goes down. In Chromium on 0.23.6: 6 after init, then 7, 8, 9.
If is necessary to execute some code in order to reproduce the bug, paste it here below:
const editor = grapesjs.init({
container: '#gjs',
height: '400px',
fromElement: true,
storageManager: false,
});
const em = editor.getModel();
setInterval(() => {
console.log('canvas:refresh listeners:', (em._events['canvas:refresh'] || []).length);
}, 1000);Registering the listener in startSort and removing it in finalizeMove fixes it — both the drop and the cancel paths go through finalizeMove. I can send a PR.
Code of Conduct
- I agree to follow this project's Code of Conduct
Source: GrapesJS/grapesjs