Issue #2459💬 AnsweredOpened December 18, 2019by kickbk1 reactions

Grapesjs adds "-2" to ids in the html with localStorage

快速解答by artf1

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:

grapesjs_adding_dash

Can you think where in your code this might be happening and why? How do I avoid this?

Thanks @artf

Answers (3)

artfDecember 20, 2019

Do you use the latest version?

kickbkDecember 20, 2019

@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.

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.