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
Find the Right GrapesJS Plugin in Seconds: Smarter Discovery Is Live
We're shipping a set of discovery upgrades. New label filters, a proper compatibility switch for GrapesJS vs Studio, one-click and a smarter sort bar.
Tutorial
GJS Market 2.0 - Donations, Tracking, Labels and Better Product Discovery
We’ve rolled out a new set of GrapesJS marketplace updates across GJS Market, focused on improving how creators distribute products
Tutorial
Preset DevFuture 2.0 — New Update Released
Preset continues evolving as a clean, production-ready starting point for building visual editors powered by GrapesJS
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.