Issue #4196💬 AnsweredOpened Mar 15, 2022by shelendravashishtha20 reactions

Ids gets changed while trying to set components on the canvas using json

Quick answerby artf

Hi @shelendravashishtha2 can you please indicate the exact steps (I need to know what is the json you're referring to)

Read full answer below ↓

Question

GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Reproducible demo link no link Describe the bug How to reproduce the bug?... use a demo json that can generate some component on the canvas, set an id in attributes ... use editor.setComponents(json)... set style using editor.setStyle() function for the same id element What is the expected behavior? ... id shouldn't be changed while getting rendered on the canvas What is the current behavior? ... id's are getting changed and because of which styles can't be implemented for the same Code of...

Answers (4)

artfMar 24, 2022

Hi @shelendravashishtha2 can you please indicate the exact steps (I need to know what is the json you're referring to)

JonathanRicheMar 25, 2022

I've seen this happen to if you don't save a reference to the CSS before using the editor.setComponents() method All of the CSS markeup from the elements id selector/reference is removed when using editor.setComponents() method The exact steps i've encountered are save a reference of the editor com...

JonathanRicheMar 25, 2022

I think I found the issue on my end using editor.getComponents().toJSON(); adds an empty "style":"" field to some of the components which is clearing out there CSS ie "components": [ { "type": "box", "style": "", "attributes": { "id": "ic7c" } }, { "type": "box", "style": "", "attributes": { "id":...

GJSBlockMay 17, 2026

Thanks for reporting this, @shelendravashishtha2. Great question about Ids gets changed while trying to set components on the canvas using json. The recommended approach with StyleManager is to use the event-driven API. Start here: Check the GrapesJS documentation for your specific module Look for...

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.