Grapesjs adds "-2" to ids in the html with localStorage
It should only happen when you append an HTML that contains an already defined ID, so the editor increments it to avoid conflicts. Are you sure you don't append the same content twice?! In any case, the function which does the check is here: https://github.com/artf/grapesjs/blob/dev/src/domcomponents/model/Component.j...
Read full answer below ↓Question
I tried to reproduce this on your demo and could not, yet I am having the strangest issue. I was hoping you could point me in the right direction when debugging this.
As soon as I store the html in localStorage and refresh the page (you will see a short pause in the screencast), grapesjs magically adds "-2" to every id in the html. See screencast below:

Can you think where in your code this might be happening and why? How do I avoid this?
Thanks @artf
Answers (3)
It should only happen when you append an HTML that contains an already defined ID, so the editor increments it to avoid conflicts. Are you sure you don't append the same content twice?!
In any case, the function which does the check is here: https://github.com/artf/grapesjs/blob/dev/src/dom_components/model/Component.js#L1262
Which is used here (when you append new content): https://github.com/artf/grapesjs/blob/dev/src/dom_components/model/Components.js#L51
Do you use the latest version?
@artf, yes I do. 0.15.9, although it's the same with prior versions. I tried to remove all the plugins to keep it all very clean, but still getting this as soon as localStorage is generated. Any ideas why or where this may get generated so I can debug?
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3579
RTE misplaced when opened right after dropping `activeOnRender` component
Version: 0.17.4 Are you able to reproduce the bug from the demo?[x] Yes[ ] No Steps to reproduce:Go to the demoDrop a "Text" block inside t...
Issue #3082
XSS Vulnerability in Live Preview
Version: 0.16.22 Are you able to reproduce the bug from the demo? [ x] Yes Steps:Click Import HTMLInsert <img src="anyimagesource.gif" onlo...
Issue #3018
Page refresh preventing after click on import
Version: 0.15.9 Are you able to reproduce the bug from the demo? Yes What is the expected behavior? Don't refresh the page after clicking o...
Issue #5425
When add a similar page just components ids will be changed
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? 117 Reproducible demo link https://jsfiddl...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →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.
Tutorial
How to Build a Production GrapesJS Editor: The Complete Walkthrough of Brief, Preset, Plugins, and Services
A complete walkthrough of building a production GrapesJS editor: how to choose a preset, pick plugins, and scope setup services without burning a sprint.
Tutorial
GrapesJS Inline RTE Plugins Update: CKEditor 5 v0.1.4 and Froala Inline Text Editor
CKEditor 5 Inline for GrapesJS v0.1.4 fixes Studio SDK toolbar clipping, iframe injection and link balloon bugs. Compare with Froala Inline — both $69.
Tutorial
Embed GrapesJS in Your SaaS: A Weekend Guide
Embed GrapesJS in your SaaS and ship a white-label page builder over a weekend. Honest tradeoffs, real code, and the plugins that close the UX gap.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.