BUG: Undo manager not working properly on undoing a remove action
Question
GrapesJS version
- I confirm to use the latest version of GrapesJS
What browser are you using?
Chrome - version 110.0.5481.100 (Official Build) (arm64)
Reproducible demo link
https://codepen.io/faisal-praella/pen/ExeNwxJ
Describe the bug
- I have added a custom columns component with a number trait name columns used for adding or removing the child component column.
- When I add a new column using the trait and undo the change it works fine but when I remove the column and undo the change an extra column is added.
- This might be because when Grapesjs undo remove change it appends the removed column and reverts the column trait as well, but this column trait change triggers
this.listenTo(this, "change:columns", this.updateColumns);which adds the new column as well. If this is the case then how to avoid listening to the column trait change on undo or when undoing the removed change Grapesjs should append the removed element first and then revert all other property/trait changes (undo in reverse order) or any other way to handle this situation?
What is the expected behavior? No extra column should be added on undoing the remove action.
What is the current behavior? An extra column is added on undoing the remove action.
Code of Conduct
- I agree to follow this project's Code of Conduct
Answers (3)
Yeah undo triggers the change:columns, in your case you could try to wrap your updateColumns changes in editor.UndoManager.skip.
updateColumns() {
editor.UndoManager.skip(() => {
// your operations
})
}
Ok I'm closing this one then and please open a new bug issue related to checkbox traits.
Thank you @artf it works, to fix this I was toggling the trait change listener by listening to undo command before & run events but this feels cleaner. The checkbox trait not getting checked or unchecked on undo/redo (trait value is updated on my end). Reproducible on Grapesjs webpage demo. Need help here as well thank you once again.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #4937
BUG: block:custom is not working on React
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? Chrome Version 110.0.5481.100 (Official Buil...
Issue #4812
BUG: Layerable property not working as expected in parent-child scenario.
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? 107.0.5304.110 (Official Build) (arm64) Re...
Issue #6269
BUG: Component model and view inits every time it's dragged over every component present in Canvas on which it can be dropped into
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Version 130.0.6723.59 (Official Bui...
Issue #4546
BUG: Component disappears when we select all the inner text and use backspace. Link component disappears even when we try to update the text.
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? Version 104.0.5112.101 (Official Build) (arm...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.