Closed am1rb closed 3 years ago
Typically inline scripts go in the body at the bottom. Try putting it there maybe?
I do not append anything by myself. The editor appends the scripts related to my components in a new script tag at the end of the generated HTML. Please take a look at this file: https://github.com/artf/grapesjs/blob/dev/src/editor/model/Editor.js#L513 I think maybe there is something wrong here. The editor appends a new script block without removing the old one.
I'm unable to reproduce this, maybe you can provide more information on the custom component itself, anyway I suspect this is a storage related issue. Are you storing then loading pages from the generated html?
I think maybe there is something wrong here. The editor appends a new script block without removing the old one.
The editor will output scripts if the wrapper contains at least 1 component containing script
property, so, there is no need to remove stuff as it is solely related to your components.
From what I can see by reading your issue If I load the above output on another editor instance
, this is completely wrong, you have to load the JSON and not the HTML. Read carefully this guide https://grapesjs.com/docs/modules/Storage.html
I guess this is just a wrong Storage configuration, so I'm closing this issue.
The issue can be reproduced if we set allowScripts: true
. I have created a reproducable demo here https://codepen.io/ashwinvalento/pen/jOJMPqx
Steps to Reproduce:
@artf @Ju99ernaut
Version:
0.16.34
Are you able to reproduce the bug from the demo?
[ ] Yes [x ] No
As I understand the code import dialog skips all the HTML scripts, so I can not reproduce the issue on the demo
What is the expected behavior?
The editor must remove dead script blocks before appending a new script block at the end of the generated HTML
Describe the bug detailed
I defined a component with script (https://grapesjs.com/docs/modules/Components-js.html) in my project. When I add this component into the editor and save the template, the editor generates the HTML and appends a script block at the end of the body to initiate the related components. The output HTML is something like this:
If I load the above output on another editor instance and save the template again it appends another script block and does not remove the old ones and the output will be something like this:
And if I repeat this behavior, It appends a new script block to my template, and it leads to having a lot of dead codes on my final template.