Repository navigation
fix(highlight): use the oniguruma engine so Go struct literals cannot freeze the page - #60
Merged
Merged
Conversation
… freeze the page Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A review froze the browser tab completely: nothing clickable, and eventually Chrome reported the page as unresponsive.
Why
Shiki's JavaScript regex engine backtracks forever on one Go construct, an anonymous struct type whose literal follows
}{with nested braces and commas:Highlighting runs synchronously during render, and a running regex cannot be interrupted, so the page locked up as soon as the window holding this code came within range of the viewport. The same file tokenizes in ~50 ms with the Oniguruma (WASM) engine, so the grammar is fine and the defect is in the JavaScript translation.
Change
highlighter.tsusescreateOnigurumaEngine(import("shiki/wasm")). The WASM (~230 KB gzipped) is a separate chunk fetched with the first grammar.Notes
App.test.tsx > light and dark > puts the choice on the root elementfails onmainas well. It is unrelated to this change.🤖 Generated with Claude Code