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.36k stars 4.05k forks source link

BUG: Deleting a component without deleting its corresponding style #5346

Closed pittleCheung closed 1 year ago

pittleCheung commented 1 year ago

GrapesJS version

What browser are you using?

latest version of Chrome

Reproducible demo link

https://grapesjs.com/demo.html

Describe the bug

How to reproduce the bug?

image

What is the expected behavior? it's style maybe reduce,

What is the current behavior? First of all, my editor only uses one page. Every time I switch pages, it will replace the current configuration with a page from the backend. Therefore, when I implement the public header and tail, I can use editor.CodeManager.getCode(component , 'html', {cssc: editor.CssComposer}); to replace the component, but I cannot use editor.CodeManager.getCode(component, 'css', {cssc: editor.CssComposer}) to replace the style, which will cause if If I operate (delete and add components) the components inside the head and tail multiple times, a lot of redundant styles will appear.

If is necessary to execute some code in order to reproduce the bug, paste it here below:

https://github.com/GrapesJS/grapesjs/issues/5263

I copying all matched styles ,so I can paste anywhere , even cross-browser paste, I find this to be extremely useful. When I delete a component, it does not remove the corresponding styles. This is a major issue, And when I copy and paste multiple times on the same website, it leads to a lot of redundant styles and easily causes style conflicts. so I can't simply expect those styles to be deleted. If possible, I would appreciate some suggestions.

Code of Conduct

pittleCheung commented 1 year ago

Extended idea from https://github.com/GrapesJS/grapesjs/issues/1855

artf commented 1 year ago

Here it's explained how to create components with related styles https://grapesjs.com/docs/modules/Components.html#components-css

Only in that case, it would be safe for the editor to delete related styles.