Issue #5379✓ SolvedOpened Sep 12, 2023by Sw33tgt4 reactions

Class modifications of components are not automatically detected

Quick answerby Sw33tgt2

For the moment, as a workaround, I added this in a editor.on('component:mount', (component) => {}); function until any feedback is received. It seems to be working well. In a case where a class is removed from the definition, the removed class will still be available on the saved component's class list, but I guess th...

Read full answer below ↓

Question

GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? Chrome Version 116Reproducible demo link https://jsfiddle.net/h5b0ndvL/1/Describe the bug When a component is re-rendered in the canvas, a new attribute added to the model definition get rendered, but a newly added class doesn't get added when the component is rendered in the canvas. The initialize function of Component.ts add the defaults attributes as well as the component's attribute. this.set('attributes', { ...(result(this, 'defaults').attributes || {}), ...(this.get('attributes') || {}), }); H...

Answers (4)

👍 Most helpfulSw33tgtSep 12, 2023

For the moment, as a workaround, I added this in a editor.on('component:mount', (component) => {}); function until any feedback is received. It seems to be working well. In a case where a class is removed from the definition, the removed class will still be available on the saved component's class...

Sw33tgtSep 20, 2023

Yeah, this is intentional with classes, with your approach you won't be able to remove defined classes from the component, they will keep being added on component init. Which is fine for when a class has been forgotten on a component and we want to add it in another version of the plugin on render....

Sw33tgtSep 12, 2023

Something like this in the initClasses() function of Component.ts would add the new classes to the element on render. Let me know what you think :

GJS HelperMay 17, 2026

The issue you've identified is a valid observation regarding how GrapesJS handles default classes versus attributes during component initialization and loading from storage. You've correctly pinpointed the difference in the Component.ts initialization logic. Root Cause When a component is loaded fr...

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.