Issue #3316Opened March 5, 2021by am1rb1 reactions

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)

Ju99ernautMarch 6, 20211 reactions

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?

Andrew-Chen-WangMarch 5, 20210 reactions

Typically inline scripts go in the body at the bottom. Try putting it there maybe?

am1rbMarch 5, 20210 reactions

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.

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

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.