Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reliable/reproducible error in a 'hello world' example using @codemirror/lang-html when typing the final character to close a <script> tag in certain situations. #1476

Closed
josephrocca opened this issue Nov 23, 2024 · 5 comments

Comments

@josephrocca
Copy link

josephrocca commented Nov 23, 2024

Describe the issue

In the reproduction link below, try typing > at the end of the first line to close the script tag. In the browser console you should see this error:

Uncaught TypeError: Cannot read properties of undefined (reading 'to')
    at Parse.moveRangeIndex (@codemirror-language.js:2392:45)
    at new Parse (@codemirror-language.js:2329:14)
    at Parser.createParse (@codemirror-language.js:2206:24)
    at Parser.startParse (@lezer-common.js:1730:21)
    at MixedParse.startInner (@lezer-common.js:1891:97)
    at MixedParse.advance (@lezer-common.js:1810:18)
    at @codemirror-language.js:363:39
    at ParseContext.withContext (@codemirror-language.js:398:20)
    at ParseContext.work (@codemirror-language.js:351:21)
    at LanguageState.apply (@codemirror-language.js:537:20)

But notice that if you delete everything from the text editor except <script></script and then try typing the final >, then it works fine.

So I guess it has something to do with the transition of the 'content' of the script tag (i.e. everything after <script>) during the transition from it no longer being considered part of the script tag, since the script tag was (about to be) closed at a position before it in the document.

Thanks!

Browser and platform

Chrome, Ubuntu 22.04

Reproduction link

https://codemirror.net/try/?c=aW1wb3J0IHtiYXNpY1NldHVwLCBFZGl0b3JWaWV3fSBmcm9tICJjb2RlbWlycm9yIgppbXBvcnQge1N0cmVhbUxhbmd1YWdlfSBmcm9tICJAY29kZW1pcnJvci9sYW5ndWFnZSI7CmltcG9ydCB7amF2YXNjcmlwdH0gZnJvbSAiQGNvZGVtaXJyb3IvbGVnYWN5LW1vZGVzL21vZGUvamF2YXNjcmlwdCI7CmltcG9ydCB7aHRtbH0gZnJvbSAiQGNvZGVtaXJyb3IvbGFuZy1odG1sIjsKCmxldCBqYXZhc2NyaXB0U3RyZWFtTG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WhlaWdodDowLjVyZW07IHdpZHRoOjEwMCU7IGJvdHRvbTowO1xuICAgICAgICA8L2Rpdj5cbiAgICAgIDwvZGl2PlxuICAgIDwvZGl2PlxuICAgIFx4M0NzY3JpcHQ+XG4gICAgICBhKCk7XG4gICAgXHgzQy9zY3JpcHQ+XG4gICAgJywKICBleHRlbnNpb25zOiBbCiAgICBiYXNpY1NldHVwLAogICAgaHRtbExhbmd1YWdlRXh0ZW5zaW9uLAogIF0sCiAgcGFyZW50OiBkb2N1bWVudC5ib2R5LAp9KTsK

@marijnh
Copy link
Member

marijnh commented Nov 24, 2024

This patch should help.

@josephrocca
Copy link
Author

That solved it, thank you! 🙏

@josephrocca
Copy link
Author

josephrocca commented Nov 26, 2024

Hey @marijnh looks like there might be an unhandled edge case. I tried my hardest to trim this down (from 3k+ lines), but the bug was really sensitive to removing random bits, so after about 30 minutes, this is what I got it down to:

If you scroll down to the bottom and try adding the final > to the end of <script></script> it'll throw the same error as before, and not let you type:

image

(Goes without saying, but this will produce invalid code, since </script> will close the parent <script> tag, but of course this should just 'break' the syntax highlighting, and not the editor itself.)

marijnh added a commit to codemirror/language that referenced this issue Nov 27, 2024
FIX: Fix an issue where a `StreamLanguage` could get confused when trying to
reuse existing parse data when the parsed range changed.

codemirror/dev#1476
@marijnh
Copy link
Member

marijnh commented Nov 27, 2024

Thanks for reproducing that. Attached patch should cover this case.

(I've updated the /try system to use URL fragments, not query parameters, to allow bigger scripts to be linked.)

@josephrocca
Copy link
Author

Thank you! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants