diff --git a/src/canvas/view/CanvasView.js b/src/canvas/view/CanvasView.js
index 576b15901..a7de63b18 100644
--- a/src/canvas/view/CanvasView.js
+++ b/src/canvas/view/CanvasView.js
@@ -415,13 +415,14 @@ module.exports = Backbone.View.extend({
* @private
*/
updateScript(view) {
+ const model = view.model;
+ const id = model.getId();
+
if (!view.scriptContainer) {
- view.scriptContainer = $('
');
+ view.scriptContainer = $(`
`);
this.getJsContainer().appendChild(view.scriptContainer.get(0));
}
- const model = view.model;
- const id = model.getId();
view.el.id = id;
view.scriptContainer.html('');
// In editor, I make use of setTimeout as during the append process of elements
diff --git a/src/dom_components/view/ComponentsView.js b/src/dom_components/view/ComponentsView.js
index 17621f2c8..be8eae94b 100644
--- a/src/dom_components/view/ComponentsView.js
+++ b/src/dom_components/view/ComponentsView.js
@@ -18,8 +18,9 @@ module.exports = Backbone.View.extend({
const tempRemove = opts.temporary;
if (!view) return;
view.remove.apply(view);
- const children = view.childrenView;
- children && children.stopListening();
+ const { childrenView, scriptContainer } = view;
+ childrenView && childrenView.stopListening();
+ scriptContainer && scriptContainer.remove();
removed.components().forEach(it => this.removeChildren(it, coll, opts));
if (em && !tempRemove) {