Attempts to load scripts to canvas maybe breaks javascript??
I haven't used inline <script> tags in a while and forgot about this caveat of the HTML parser. Closing this.
Read full answer below βQuestion
Version: 0.16.44
Are you able to reproduce the bug from the demo?
[ ] Yes [x] No
What is the expected behavior? Legit anything else
Describe the bug detailed
I was attempting to load scripts into the canvas. My first attempt was scripts: [] and then I ran into the synchronization issue mentioned in this PR's thread: https://github.com/artf/grapesjs/pull/67
I saw an example from @artf showing another way to do it with a property called components. Doing this broke the javascript parser. I'm not kidding; I posted a screenshot to prove it.
Also interesting to note: the text saying "TAG LOAD" in my console is coming from the script I was trying to load. So it... worked? Despite the page crashing due to the syntax being "invalid".
What is the current behavior? Seems to break Javascript parser?? O.o <img width="795" alt="Screen Shot 2021-03-11 at 2 31 27 AM" src="https://user-images.githubusercontent.com/7225168/110752290-126c2980-8213-11eb-87f4-a32ff83efc0b.png"> <img width="359" alt="Screen Shot 2021-03-11 at 2 40 31 AM" src="https://user-images.githubusercontent.com/7225168/110752363-2f086180-8213-11eb-9361-ed26ebae1fe1.png"> <img width="991" alt="Screen Shot 2021-03-11 at 2 42 18 AM" src="https://user-images.githubusercontent.com/7225168/110752605-7d1d6500-8213-11eb-9f5a-b63816c411f9.png">
Answers (2)
I haven't used inline <script> tags in a while and forgot about this caveat of the HTML parser. Closing this.
Thanks for reporting this, @KernelDeimos.
The issue with Attempts to load scripts to canvas maybe breaks javascript?? appears to be a race condition or state management timing problem. This typically happens when component lifecycle events and DOM modifications overlap, creating an inconsistent state.
What to try:
- Add a setTimeout wrapper to ensure the DOM has settled:
setTimeout(() => {
// your operation here
}, 0);
-
Check initialization order β make sure components are fully loaded before you interact with them
-
Use the editor's event system β listen to completion events:
editor.on('component:mount', (component) => {
// safe to interact with component here
});
Recommended next steps:
- Test with the latest GrapesJS version if you haven't
- Provide a minimal reproducible example (CodeSandbox) β this helps the team identify the root cause faster
- Include GrapesJS version, browser, and console errors in your report
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3491
iframe does not save src / does not recognize iframes after load
Version: 0.17.4 Are you able to reproduce the bug from the demo?[ ] Yes[X] No What is the expected behavior?After inserting an iFrame that...
Issue #3435
Scrollable onStart/onEnd/updateTarget not Overridable
Version: 0.17.3 Are you able to reproduce the bug from the demo?[ ] Yes[X] No What is the expected behavior? Being able to override onStart...
Issue #5705
Component tools misalign when the editor is resized
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome v122 Reproducible demo link https:/...
Issue #3295
BUG (v0.16.41): Button component with draggable property is not working properly
Version: v0.16.41 Are you able to reproduce the bug from the demo? [ ] Yes [ ] No What is the expected behavior? When we have a button with...
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
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.
Tutorial
Ship to Production Faster: Whatβs New in GrapesJS Shadcn
Supercharge your page builder! GrapesJS Shadcn adds live drag previews, rich text / commands, dynamic data, and canvas presets to ship to prod faster.
Tutorial
How to Build a Production GrapesJS Editor: The Complete Walkthrough of Brief, Preset, Plugins, and Services
A complete walkthrough of building a production GrapesJS editor: how to choose a preset, pick plugins, and scope setup services without burning a sprint.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.