BUG: Undo Manager creates Duplicate CSS during custom command
Question
GrapesJS version
- I confirm to use the latest version of GrapesJS
What browser are you using?
103.0.5060.66 (Official Build) (64-bit) (cohort: Stable)
Reproducible demo link
https://codesandbox.io/s/cranky-morning-fh5diz?file=/index.js
Describe the bug
How to reproduce the bug?
- Drop the custom block "picture" into the frame and resize.
- Look at markup preview, and you will see two ids in the css with duplicate markup (picture id and img id)
- "Undo" until resize changes again
- Look at markup preview, and now css markup has duplicate id of picture element, preventing further styling
What is the expected behavior?
The picture element relies on css styling of the img tag for dimensions to display properly. While exploring this, I created a command sync-styles that will duplicate any styles defined on the parent to the child (pending if a property is present). Expected behavior is that the styles will be completely synced, even when Undo Manager is called
What is the current behavior?
The command sync-styles works as expected until the Undo Manager is activated. I'm not sure exactly which piece is causing the break, but currently the styles for the img id are gone, and there are two definitions of style for the picture id.
I actually created the command in hopes that that would fix the error, since originally I just executed the code in the watched event handler for style:property:update. Regardless of where I execute the style updates, the UndoManager breaks the same way.
Code of Conduct
- I agree to follow this project's Code of Conduct
Answers (1)
I'm not sure exactly what is happening but I'd suggest switching to styleable:change event and pass its options to setStyle, eg.
editor.on("styleable:change", (model, prop, opts) => {
let component = editor.getSelected();
if (component?.attributes.styleShared) {
let child = component.attributes.components.models.filter(
(m) => m.attributes.tagName === component.attributes.styleShared
)[0];
let styles = component.getStyle();
child.setStyle(styles, opts);
}
});
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3939
BUG: Disabled drag and drop in preview
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? v95Reproducible demo link https://codesandbo...
Issue #4920
BUG: Missed localization keys for de locale
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Not browser related Reproducible demo link...
Issue #4754
BUG: Closing `</script>` tag not escaped for script properties
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Version 107.0.5304.122 (64-bit) Rep...
Issue #5297
BUG: getJS not working
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? Version 115.0.5790.171 (Official Build) (64-...
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.