There seems to be a bug in the code highlighting

Hello! Thank you very much for providing such excellent code!

Problems:

First, add code block highlight for markdown, then assign a long text to DOC of editor, as shown in the picture, and then I modify the content of one code block, for example, change HTML to JavaScript, the console will display a red error message, and the subsequent operations will not be operated, such as deletion, writing, etc! Please check my GIF pictures for details

There is another situation. For example, in my project, I save the text in the current editor as a draft every five seconds. For example, I’m typing javasc. But the input is not complete, and then save the draft, refresh the page, the page will cause an error, and then the next operation is not executable. Please see the GIF pictures I recorded for details.


Here is a simple example I wrote, which may be helpful for your debugging。

The escape character is added here to prevent the parsing exception of the current article. Therefore, when using it, you need to delete the escape character

<textarea>
\`\`\`html
<div></div>
\`\`\`
\`\`\`html
<div></div>
\`\`\`
<!--Look here. I made a mistake here on purpose-->
\`\`\`javasc
<div></div>
\`\`\`
\`\`\`html
<div></div>
\`\`\`
\`\`\`html
<div></div>
\`\`\`
</textarea>
import theme from './theme'; // theme.js is the style file defined for highlighting
EditorState.create({
  doc: document.querySelector("textarea").value,
  extensions: [
    theme(),
    markdown({
      base: markdownLanguage,
      codeLanguages: languages
   }),
  ]
})

Thank you very much for any help!

As my code is compressed, I try to see the location of the problem for you

Could you check if your node_modules tree has multiple instances of lezer-tree in it? That might lead to this error (by breaking instanceof checks).

This is my node_ Modules folder

That only shows one level — when a package is duplicated, it’ll be under some dependency’s own node_modules folder. Try npm ls | grep lezer-tree or something like that.

I have found out the cause of this problem. This happens when I set the preserveEntrySignatures option of rollup to false. I tried to set this option value to “strict” and there was no problem.