The best way to control Claude Code, Codex and more from any computer or phone
fix(web): stop highlighter freezes and worker spin by using the Oniguruma WASM engine (#8360)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Zico committed
Sep 1, 2026 at 18:06 UTC
feb3ea7ebf83de2e301adb1f20300b262773ec54
7 files changed
+23
-2
apps/web/src/components/DiffPanel.tsx
+2
@@ -37,6 +37,7 @@ import {
37
resolveDiffThemeName,
38
resolveFileDiffPath,
39
} from "../lib/diffRendering";
40
+import { PREFERRED_HIGHLIGHTER } from "../lib/syntaxHighlighting";
41
import { areAllDiffFilesCollapsed, toggleAllDiffFiles } from "../lib/diffCollapse";
42
import { useTurnDiffSummaries } from "../hooks/useTurnDiffSummaries";
43
import { useWorkspaceMutationRefresh } from "../hooks/useWorkspaceMutationRefresh";
@@ -948,6 +949,7 @@ export default function DiffPanel({
949
lineDiffType: "none",
950
overflow: wordWrap ? "wrap" : "scroll",
951
theme: resolveDiffThemeName(resolvedTheme),
952
+ preferredHighlighter: PREFERRED_HIGHLIGHTER,
953
themeType: resolvedTheme as DiffThemeType,
954
stickyHeaders: true,
955
...(loadDiffFiles ? { loadDiffFiles } : {}),
apps/web/src/components/DiffWorkerPoolProvider.tsx
+2
@@ -4,6 +4,7 @@ import * as Schema from "effect/Schema";
4
import { useEffect, useMemo, type ReactNode } from "react";
5
import { useTheme } from "../hooks/useTheme";
6
import { resolveDiffThemeName, type DiffThemeName } from "../lib/diffRendering";
7
+import { PREFERRED_HIGHLIGHTER } from "../lib/syntaxHighlighting";
8
9
export class DiffWorkerError extends Schema.TaggedErrorClass<DiffWorkerError>()("DiffWorkerError", {
10
operation: Schema.Literals(["create-worker", "get-render-options", "set-render-options"]),
@@ -73,6 +74,7 @@ export function DiffWorkerPoolProvider({ children }: { children?: ReactNode }) {
74
}}
75
highlighterOptions={{
76
theme: diffThemeName,
77
+ preferredHighlighter: PREFERRED_HIGHLIGHTER,
78
tokenizeMaxLineLength: 1_000,
79
useTokenTransformer: true,
80
}}
apps/web/src/components/chat/MessagesTimeline.tsx
+2
@@ -59,6 +59,7 @@ import {
59
resolveDiffThemeName,
60
resolveFileDiffPath,
61
} from "../../lib/diffRendering";
62
+import { PREFERRED_HIGHLIGHTER } from "../../lib/syntaxHighlighting";
63
import ChatMarkdown, { ChatMarkdownAssetImage } from "../ChatMarkdown";
64
import {
65
BotIcon,
@@ -2060,6 +2061,7 @@ function UserMessageReviewCommentCard({ comment }: { comment: ReviewCommentConte
2061
collapsed: false,
2062
diffStyle: "unified",
2063
theme: resolveDiffThemeName(ctx.resolvedTheme),
2064
+ preferredHighlighter: PREFERRED_HIGHLIGHTER,
2065
}}
2066
/>
2067
))}
apps/web/src/components/files/FilePreviewPanel.tsx
+3
@@ -31,6 +31,7 @@ import { useTheme } from "~/hooks/useTheme";
31
import { getLocalStorageItem, setLocalStorageItem, useLocalStorage } from "~/hooks/useLocalStorage";
32
import { useWorkspaceMutationRefresh } from "~/hooks/useWorkspaceMutationRefresh";
33
import { DIFF_SURFACE_THEME_UNSAFE_CSS, resolveDiffThemeName } from "~/lib/diffRendering";
34
+import { PREFERRED_HIGHLIGHTER } from "~/lib/syntaxHighlighting";
35
import { cn } from "~/lib/utils";
36
import { isPreviewSupportedInRuntime } from "~/previewStateStore";
37
import { resolvePathLinkTarget } from "~/terminal-links";
@@ -755,6 +756,7 @@ function EditableFileSurface({
756
onLineSelectionEnd: handleLineSelectionEnd,
757
overflow: wordWrap ? "wrap" : "scroll",
758
theme: resolveDiffThemeName(resolvedTheme),
759
+ preferredHighlighter: PREFERRED_HIGHLIGHTER,
760
themeType: resolvedTheme,
761
unsafeCSS: FILE_LINK_REVEAL_UNSAFE_CSS,
762
onPostRender: handlePostRender,
@@ -1149,6 +1151,7 @@ export default function FilePreviewPanel({
1151
disableFileHeader: true,
1152
overflow: wordWrap ? "wrap" : "scroll",
1153
theme: resolveDiffThemeName(resolvedTheme),
1154
+ preferredHighlighter: PREFERRED_HIGHLIGHTER,
1155
themeType: resolvedTheme,
1156
unsafeCSS: FILE_LINK_REVEAL_UNSAFE_CSS,
1157
onPostRender: onFilePostRender,
apps/web/src/components/pullRequest/PullRequestCodeTab.tsx
+2
@@ -42,6 +42,7 @@ import {
42
resolveFileDiffPreviousPath,
43
type RenderablePatch,
44
} from "~/lib/diffRendering";
45
+import { PREFERRED_HIGHLIGHTER } from "~/lib/syntaxHighlighting";
46
import { cn } from "~/lib/utils";
47
import { createPullRequestDiffFileContentsLoader } from "~/lib/diffFileContents";
48
import {
@@ -743,6 +744,7 @@ export function PullRequestCodeTab({
744
lineDiffType: "none" as const,
745
overflow: wordWrap ? ("wrap" as const) : ("scroll" as const),
746
theme: resolveDiffThemeName(resolvedTheme),
747
+ preferredHighlighter: PREFERRED_HIGHLIGHTER,
748
themeType: resolvedTheme,
749
stickyHeaders: true,
750
loadDiffFiles,
apps/web/src/components/settings/SettingsFontPreviews.tsx
+2
-1
@@ -5,6 +5,7 @@ import { terminalThemeFromApp } from "../ThreadTerminalDrawer";
5
import { useTheme } from "../../hooks/useTheme";
6
import { DISCONNECTED_COMPOSER_PLACEHOLDER } from "../../composerPlaceholder";
7
import { resolveDiffThemeName, type DiffThemeName } from "../../lib/diffRendering";
8
+import { PREFERRED_HIGHLIGHTER } from "../../lib/syntaxHighlighting";
9
import { GhosttyTerminalSurface } from "~/terminal/ghostty/surface";
10
11
// The font previews are the real surfaces, not lookalikes: the composer's
@@ -79,7 +80,7 @@ function loadDiffPreviewHtml(theme: DiffThemeName): Promise<readonly string[]> {
80
if (promise === undefined) {
81
promise = preloadPatchFile({
82
patch: DIFF_PREVIEW_PATCH,
82
- options: { diffStyle: "unified", theme },
83
+ options: { diffStyle: "unified", theme, preferredHighlighter: PREFERRED_HIGHLIGHTER },
84
}).then((results) => results.map((result) => result.prerenderedHTML));
85
diffPreviewHtmlByTheme.set(theme, promise);
86
}
apps/web/src/lib/syntaxHighlighting.ts
+10
-1
@@ -1,11 +1,20 @@
1
import {
2
getSharedHighlighter,
3
type DiffsHighlighter,
4
+ type HighlighterTypes,
5
type SupportedLanguages,
6
} from "@pierre/diffs";
7
8
import { resolveDiffThemeName } from "./diffRendering";
9
10
+/**
11
+ * Always highlight with the Oniguruma WASM engine — the JS regex engine can
12
+ * backtrack catastrophically and hang the tokenizing thread. The shared
13
+ * highlighter is a first-caller-wins singleton, so every creation site must
14
+ * pass this value.
15
+ */
16
+export const PREFERRED_HIGHLIGHTER: HighlighterTypes = "shiki-wasm";
17
+
18
const highlighterPromiseCache = new Map<string, Promise<DiffsHighlighter>>();
19
20
export function getSyntaxHighlighterPromise(language: string): Promise<DiffsHighlighter> {
@@ -15,7 +24,7 @@ export function getSyntaxHighlighterPromise(language: string): Promise<DiffsHigh
24
const promise = getSharedHighlighter({
25
themes: [resolveDiffThemeName("dark"), resolveDiffThemeName("light")],
26
langs: [language as SupportedLanguages],
18
- preferredHighlighter: "shiki-js",
27
+ preferredHighlighter: PREFERRED_HIGHLIGHTER,
28
}).catch((error) => {
29
if (language === "text") {
30
highlighterPromiseCache.delete(language);