GrapesJS / grapesjs

Free and Open source Web Builder Framework. Next generation tool for building templates without coding
https://grapesjs.com
BSD 3-Clause "New" or "Revised" License
22.38k stars 4.06k forks source link

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

Closed kickbk closed 4 years ago

kickbk commented 4 years ago

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

artf commented 4 years ago

Do you use the latest version?

kickbk commented 4 years ago

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

artf commented 4 years ago

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