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/domcomponen...
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
Messaging on gjs.market: talk to a studio before you buy, not after
We've launched private messaging between buyers and studios. One thread per buyerβstudio pair, the whole history in one place.
Tutorial
Vanilla GrapesJS vs GrapesJS With Plugins: What You Actually Get Out of the Box (2026)
New to GrapesJS? See exactly what the stock editor gives you, where it falls short, and which plugins close the gaps β a beginner-friendly 2026 comparison
Tutorial
Lighthouse for GrapesJS: Audit Accessibility and SEO Without Leaving the Editor
Live WCAG 2.1/2.2 accessibility auditor + SEO manager for GrapesJS. Every finding is bound to the exact component β click to select, then one-click fix.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.