Skip to content

fix(highlight): use the oniguruma engine so Go struct literals cannot freeze the page - #60

Merged
asnunes merged 1 commit into
mainfrom
fix/go-highlight-freeze
Oct 5, 2026
Merged

asnunes merged 1 commit into
mainfrom
fix/go-highlight-freeze

Conversation

@asnunes

@asnunes asnunes commented Oct 5, 2026

Copy link
Copy Markdown
Owner

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:

require.NoError(t, json.NewEncoder(w).Encode(struct {
	Items []contracts.Fact `json:"items"`
}{Items: []contracts.Fact{{Candidate: contracts.Candidate{Reference: reference, ChatID: "conversation", BusinessObjectID: "appointment", SourceFlow: "reminder"}, Eligible: true, Revision: "rev"}}}))

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.ts uses createOnigurumaEngine(import("shiki/wasm")). The WASM (~230 KB gzipped) is a separate chunk fetched with the first grammar.
  • Regression test with the real snippet. It hangs on the old engine and passes in milliseconds on the new one.

Notes

App.test.tsx > light and dark > puts the choice on the root element fails on main as well. It is unrelated to this change.

🤖 Generated with Claude Code

… freeze the page

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 5, 2026 17:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@asnunes
asnunes merged commit 81fe905 into main Oct 5, 2026
2 checks passed
@asnunes
asnunes deleted the fix/go-highlight-freeze branch October 5, 2026 18:19
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

Successfully merging this pull request may close these issues.

2 participants