Component script function runs twice after page save
As explained here you should not reimport the output HTML to edit the project, only the JSON.
Read full answer below βQuestion
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? 112.0.5615.137 (Official Build) (arm64) Reproducible demo link https://grapesjs.com/demo.html Describe the bug Component definition: When dropped, saved, and reload there are two places that call the same script. One in the saved HTML/JSON and one added by Grapesjs itself. How to reproduce the bug?Add a custom component type with a script function.Drop it and save the page.Reloading the page runs the script function twice. What is the expected behavior? The script function should be running only o...
Answers (2)
As explained here you should not reimport the output HTML to edit the project, only the JSON.
The issue you've encountered where a component's script function runs twice after saving and reloading the page is a known behavior (or a bug, depending on the perspective) in GrapesJS's script management system. It stems from how GrapesJS handles and serializes component scripts for both the edito...
Related Questions and Answers
Continue research with similar issue discussions.
Issue #6152
CSS added via custom code persists after custom code component is removed
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? any Reproducible demo link https://grapesj...
Issue #4752
Component with pointer-events: 'all' (except wrapper) or editable component are draggable & droppable to itself.
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? Chrome 107.0.5304.121 (Official Build) (arm6...
Issue #5173
Editor.Css.setRule API not working as expected, it is not updating the rule existing rule.
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Version 112.0.5615.137 (Official Build) (a...
Issue #5346
Deleting a component without deleting its corresponding style
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? latest version of Chrome Reproducible demo...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins βPremium plugins ship with support, regular updates, and production-ready features β save days of integration work.
Browse premium plugins βRelated tutorials
In-depth guides on the same topic.
Tutorial
Introducing GJS.Market Services: ship your GrapesJS editor without the integration risk
It's everything that usually eats weeks of engineering time, scoped and priced up front. No open-ended hourly surprises.
Tutorial
GrapesJS custom components guide (2026)
Define custom GrapesJS components with DomComponents.addType: detection with isComponent, a model with traits and defaults, and a view for canvas behavior.
Tutorial
Building an AI-Assisted Document Engine with Next.js, GrapesJS, and the AI SDK
Transform your static template editor into an intelligent, generative design workspace with Vercel AI SDK, AI Elements and Next.js.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.