WIP: Guard tagHighlighter style() against null/undefined tags #20
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/tags-not-iterable-when-lezer-common-duplicated"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
When
@lezer/commonis accidentally instantiated multiple times (e.g. by a bundler such as Vite's esbuild pre-bundler creating duplicate module instances),NodePropIDs from one instance can collide with prop IDs from another. This causesgetStyleTags()to return an object whose.tagsproperty isundefinedinstead of aRule, which then crashes the highlighter with:This is a known real-world issue reported in:
The root cause is always the same: duplicate
@lezer/commoninstances leading to colliding prop IDs, which meansnode.type.prop(ruleNodeProp)can return an unrelated object (without a.tagsarray) instead of aRule.Fix
Make
tagHighlighter'sstyle()function defensive by treating anull/undefinedtags argument as an empty array, so the plugin degrades gracefully (no highlighting) instead of crashing the entire editor.Also widens the
Highlighterinterface'sstyle()signature toreadonly Tag[] | nullto reflect this.This does not prevent the underlying bundler misconfiguration but it stops the editor from becoming completely non-functional when it occurs.
This won't solve the problem (you'll still get confused highlighting), and when you have duplicated packages, in a web context, you really want to know, and fix it, rather than suppress the errors. So this is not something I want to merge.
@marijnh thanks, I was about to extend this with more than just the agent generated text, but thanks for clarifying, this is now breaking codemirror for a while and I'm trying to fix it.
@marijnh Could you give me a hint what you mean with
I'm not sure what to fix, or rather where this error originates from
Your package manager is installing multiple copies of packages. The reason you want to fix this is that it'll make you users download a lot more JavaScript than they need, and it'll break some libraries (including Lezer and CodeMirror). You either have some incompatible versions in your dependencies (look for 0.x versions of CodeMirror or Lezer packages), or you use a dumb tool like yarn, which is really bad at deduplicating packages. Clearing your package lock and reinstalling from scratch often helps.
Awesome that really helped I updated my
package.jsonand now the problem is gone 🎉The cause
@codemirror/language@6.12.2 requires @lezer/common ^1.5.0, but @lezer/highlight@1.2.3 only declares ^1.3.0. pnpm installs both 1.4.0 and 1.5.1 side-by-side.
this results in
Pull request closed