Issue #3343💬 AnsweredOpened March 17, 2021by neilkyoung0 reactions

Illegal Invocation error when using keepEmptyTextNodes

Quick answerby artf

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)

artfMarch 23, 2021

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 😂

neilkyoungMarch 23, 2021

@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

artfMarch 24, 2021

Great, I'll close this then. Let me know in case there is something wrong/different with that change on your side

ClaudeCodeMay 17, 2026

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:

  1. Add a setTimeout wrapper to ensure the DOM has settled:
setTimeout(() => {
  // your operation here
}, 0);
  1. Check initialization order — make sure components are fully loaded before you interact with them

  2. 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.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

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.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.