Illegal Invocation error when using keepEmptyTextNodes
Well, yeah makes sense, probably we should take the first "valid" element (the one which actually supports matches). But I'm also curious to know your case for the use of keepEmptyTextNodes. A few days ago I was actually thinking about removing it π
Read full answer below βQuestion
Version: 0.16.44
Are you able to reproduce the bug from the demo?
- Yes
- No
Set editor.Parser.getConfig().keepEmptyTextNodes = true; in the console and then attempt to drag a form into a 2 column plugin.
What is the expected behavior?
Describe the bug detailed
From my observation a keepEmptyTextNodes will throw an error with Sorter.js when a droppable attribute is defined. When it tries to figure out validity it ends up getting the actual text node ahead of the content which means that the matches comparison fails (text node doesn't support matches).
What is the current behavior? Problem area seems to be the below in Sorter.js
const tempModel = comps.add(dropContent, { ...opts, temporary: 1 });
dropModel = comps.remove(tempModel, opts);
dropModel = dropModel instanceof Array ? dropModel[0] : dropModel;
this.dropModel = dropModel;
This is due to the tempModel then having the text nodes that may wrap the content defined in the block. When it is removed to obtain the dropModel we end up with the text node and not the actual content because of the parsing options.
Describe the bug detailed Attempt to drop plugin 2 into plugin 1 and note an illegal invocation error in the console.
https://codepen.io/neilkyoung/pen/abBxqmY
Are you able to attach screenshots, screencasts or a live demo?
- Yes
- No
https://codepen.io/neilkyoung/pen/abBxqmY
https://user-images.githubusercontent.com/3243711/111464171-5762f500-8718-11eb-9765-11d394c2c581.mp4
Answers (4)
Well, yeah makes sense, probably we should take the first "valid" element (the one which actually supports matches).
But I'm also curious to know your case for the use of keepEmptyTextNodes. A few days ago I was actually thinking about removing it π
@artf A system we use for web page authoring implements this. Although we have now managed to convince them to disable this thanks to your comment above :-D
Great, I'll close this then. Let me know in case there is something wrong/different with that change on your side
Thanks for reporting this, @neilkyoung.
The issue with Illegal Invocation error when using keepEmptyTextNodes 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 #3622
I18n functionality
Version: latest Are you able to reproduce the bug from the demo?[] Yes[ ] No What is the expected behavior? to editor.I18n.setLocale("es")...
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...
Issue #3693
AdoptStylesheet not supported in grapesJS
Version: You can get the version by typing grapesjs.version into the console 0.17.22 Are you able to reproduce the bug from the demo?[x] Ye...
Issue #3305
(v0.16.41) Button not set as active on click
Version: v0.16.41 Are you able to reproduce the bug from the demo? [ ] Yes [x] No What is the expected behavior? When I click on a button,...
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
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.
Tutorial
GrapesJS Inline RTE Plugins Update: CKEditor 5 v0.1.4 and Froala Inline Text Editor
CKEditor 5 Inline for GrapesJS v0.1.4 fixes Studio SDK toolbar clipping, iframe injection and link balloon bugs. Compare with Froala Inline β both $69.
Tutorial
Embed GrapesJS in Your SaaS: A Weekend Guide
Embed GrapesJS in your SaaS and ship a white-label page builder over a weekend. Honest tradeoffs, real code, and the plugins that close the UX gap.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.