BUG: The editor does not remove the dead script blocks
Question
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:
<head>
<!-- Generated HTML -->
<script>/* The appended script block to initiate my custom components */</script>
</head>
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:
<head>
<!-- Generated HTML -->
<script>/* The appended script block to initiate my custom block */</script>
<script>/* A new script block to initiate my custom block */</script>
</head>
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.
<head>
<!-- Generated HTML -->
<script>/* Dead Script 1 */</script>
<script>/* Dead Script 2 */</script>
<script>/* .... */</script>
<script>/* A new script block to initiate my custom block */</script>
</head>
Answers (3)
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?
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.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3441
BUG: Parser breaks `mj-style` as of 16.30
Version: All Grapesjs version from 16.30 to now have this issues. Are you able to reproduce the bug from the demo?[x] Yes[ ] No What is the...
Issue #3027
BUG: Image asset manager, on remove no ability to re-upload the same image that was removed
Are you able to reproduce the bug from the demo? No, in the image asset manager in the demo there is no option to remove images. What is th...
Issue #2982
BUG: Executing editor.load(x) on x = editor.store() results in error.
Version: 0.16.18 Are you able to reproduce the bug from the demo? [X ] Yes [ ] No What is the expected behavior? I would expect that assets...
Issue #3015
BUG: HTML exported from the demo not responsive to screen size
Version: 0.16.22 Are you able to reproduce the bug from the demo? [] Yes [ ] No What is the expected behavior? the exported html should be...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.