fix(web): stop highlighter freezes and worker spin by using the Oniguruma WASM engine (#8360)
Co-authored-by: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
ea71a19d41
commit
feb3ea7ebf
7 files changed
+23
-2
No files matched your search
@@ -37,6 +37,7 @@ import {
|
||||
resolveDiffThemeName,
|
||||
resolveFileDiffPath,
|
||||
} from "../lib/diffRendering";
|
||||
import { PREFERRED_HIGHLIGHTER } from "../lib/syntaxHighlighting";
|
||||
import { areAllDiffFilesCollapsed, toggleAllDiffFiles } from "../lib/diffCollapse";
|
||||
import { useTurnDiffSummaries } from "../hooks/useTurnDiffSummaries";
|
||||
import { useWorkspaceMutationRefresh } from "../hooks/useWorkspaceMutationRefresh";
|
||||
@@ -948,6 +949,7 @@ export default function DiffPanel({
|
||||
lineDiffType: "none",
|
||||
overflow: wordWrap ? "wrap" : "scroll",
|
||||
theme: resolveDiffThemeName(resolvedTheme),
|
||||
preferredHighlighter: PREFERRED_HIGHLIGHTER,
|
||||
themeType: resolvedTheme as DiffThemeType,
|
||||
stickyHeaders: true,
|
||||
...(loadDiffFiles ? { loadDiffFiles } : {}),
|
||||
|
||||
@@ -4,6 +4,7 @@ import * as Schema from "effect/Schema";
|
||||
import { useEffect, useMemo, type ReactNode } from "react";
|
||||
import { useTheme } from "../hooks/useTheme";
|
||||
import { resolveDiffThemeName, type DiffThemeName } from "../lib/diffRendering";
|
||||
import { PREFERRED_HIGHLIGHTER } from "../lib/syntaxHighlighting";
|
||||
|
||||
export class DiffWorkerError extends Schema.TaggedErrorClass<DiffWorkerError>()("DiffWorkerError", {
|
||||
operation: Schema.Literals(["create-worker", "get-render-options", "set-render-options"]),
|
||||
@@ -73,6 +74,7 @@ export function DiffWorkerPoolProvider({ children }: { children?: ReactNode }) {
|
||||
}}
|
||||
highlighterOptions={{
|
||||
theme: diffThemeName,
|
||||
preferredHighlighter: PREFERRED_HIGHLIGHTER,
|
||||
tokenizeMaxLineLength: 1_000,
|
||||
useTokenTransformer: true,
|
||||
}}
|
||||
|
||||
@@ -59,6 +59,7 @@ import {
|
||||
resolveDiffThemeName,
|
||||
resolveFileDiffPath,
|
||||
} from "../../lib/diffRendering";
|
||||
import { PREFERRED_HIGHLIGHTER } from "../../lib/syntaxHighlighting";
|
||||
import ChatMarkdown, { ChatMarkdownAssetImage } from "../ChatMarkdown";
|
||||
import {
|
||||
BotIcon,
|
||||
@@ -2060,6 +2061,7 @@ function UserMessageReviewCommentCard({ comment }: { comment: ReviewCommentConte
|
||||
collapsed: false,
|
||||
diffStyle: "unified",
|
||||
theme: resolveDiffThemeName(ctx.resolvedTheme),
|
||||
preferredHighlighter: PREFERRED_HIGHLIGHTER,
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
|
||||
@@ -31,6 +31,7 @@ import { useTheme } from "~/hooks/useTheme";
|
||||
import { getLocalStorageItem, setLocalStorageItem, useLocalStorage } from "~/hooks/useLocalStorage";
|
||||
import { useWorkspaceMutationRefresh } from "~/hooks/useWorkspaceMutationRefresh";
|
||||
import { DIFF_SURFACE_THEME_UNSAFE_CSS, resolveDiffThemeName } from "~/lib/diffRendering";
|
||||
import { PREFERRED_HIGHLIGHTER } from "~/lib/syntaxHighlighting";
|
||||
import { cn } from "~/lib/utils";
|
||||
import { isPreviewSupportedInRuntime } from "~/previewStateStore";
|
||||
import { resolvePathLinkTarget } from "~/terminal-links";
|
||||
@@ -755,6 +756,7 @@ function EditableFileSurface({
|
||||
onLineSelectionEnd: handleLineSelectionEnd,
|
||||
overflow: wordWrap ? "wrap" : "scroll",
|
||||
theme: resolveDiffThemeName(resolvedTheme),
|
||||
preferredHighlighter: PREFERRED_HIGHLIGHTER,
|
||||
themeType: resolvedTheme,
|
||||
unsafeCSS: FILE_LINK_REVEAL_UNSAFE_CSS,
|
||||
onPostRender: handlePostRender,
|
||||
@@ -1149,6 +1151,7 @@ export default function FilePreviewPanel({
|
||||
disableFileHeader: true,
|
||||
overflow: wordWrap ? "wrap" : "scroll",
|
||||
theme: resolveDiffThemeName(resolvedTheme),
|
||||
preferredHighlighter: PREFERRED_HIGHLIGHTER,
|
||||
themeType: resolvedTheme,
|
||||
unsafeCSS: FILE_LINK_REVEAL_UNSAFE_CSS,
|
||||
onPostRender: onFilePostRender,
|
||||
|
||||
@@ -42,6 +42,7 @@ import {
|
||||
resolveFileDiffPreviousPath,
|
||||
type RenderablePatch,
|
||||
} from "~/lib/diffRendering";
|
||||
import { PREFERRED_HIGHLIGHTER } from "~/lib/syntaxHighlighting";
|
||||
import { cn } from "~/lib/utils";
|
||||
import { createPullRequestDiffFileContentsLoader } from "~/lib/diffFileContents";
|
||||
import {
|
||||
@@ -743,6 +744,7 @@ export function PullRequestCodeTab({
|
||||
lineDiffType: "none" as const,
|
||||
overflow: wordWrap ? ("wrap" as const) : ("scroll" as const),
|
||||
theme: resolveDiffThemeName(resolvedTheme),
|
||||
preferredHighlighter: PREFERRED_HIGHLIGHTER,
|
||||
themeType: resolvedTheme,
|
||||
stickyHeaders: true,
|
||||
loadDiffFiles,
|
||||
|
||||
@@ -5,6 +5,7 @@ import { terminalThemeFromApp } from "../ThreadTerminalDrawer";
|
||||
import { useTheme } from "../../hooks/useTheme";
|
||||
import { DISCONNECTED_COMPOSER_PLACEHOLDER } from "../../composerPlaceholder";
|
||||
import { resolveDiffThemeName, type DiffThemeName } from "../../lib/diffRendering";
|
||||
import { PREFERRED_HIGHLIGHTER } from "../../lib/syntaxHighlighting";
|
||||
import { GhosttyTerminalSurface } from "~/terminal/ghostty/surface";
|
||||
|
||||
// The font previews are the real surfaces, not lookalikes: the composer's
|
||||
@@ -79,7 +80,7 @@ function loadDiffPreviewHtml(theme: DiffThemeName): Promise<readonly string[]> {
|
||||
if (promise === undefined) {
|
||||
promise = preloadPatchFile({
|
||||
patch: DIFF_PREVIEW_PATCH,
|
||||
options: { diffStyle: "unified", theme },
|
||||
options: { diffStyle: "unified", theme, preferredHighlighter: PREFERRED_HIGHLIGHTER },
|
||||
}).then((results) => results.map((result) => result.prerenderedHTML));
|
||||
diffPreviewHtmlByTheme.set(theme, promise);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
import {
|
||||
getSharedHighlighter,
|
||||
type DiffsHighlighter,
|
||||
type HighlighterTypes,
|
||||
type SupportedLanguages,
|
||||
} from "@pierre/diffs";
|
||||
|
||||
import { resolveDiffThemeName } from "./diffRendering";
|
||||
|
||||
/**
|
||||
* Always highlight with the Oniguruma WASM engine — the JS regex engine can
|
||||
* backtrack catastrophically and hang the tokenizing thread. The shared
|
||||
* highlighter is a first-caller-wins singleton, so every creation site must
|
||||
* pass this value.
|
||||
*/
|
||||
export const PREFERRED_HIGHLIGHTER: HighlighterTypes = "shiki-wasm";
|
||||
|
||||
const highlighterPromiseCache = new Map<string, Promise<DiffsHighlighter>>();
|
||||
|
||||
export function getSyntaxHighlighterPromise(language: string): Promise<DiffsHighlighter> {
|
||||
@@ -15,7 +24,7 @@ export function getSyntaxHighlighterPromise(language: string): Promise<DiffsHigh
|
||||
const promise = getSharedHighlighter({
|
||||
themes: [resolveDiffThemeName("dark"), resolveDiffThemeName("light")],
|
||||
langs: [language as SupportedLanguages],
|
||||
preferredHighlighter: "shiki-js",
|
||||
preferredHighlighter: PREFERRED_HIGHLIGHTER,
|
||||
}).catch((error) => {
|
||||
if (language === "text") {
|
||||
highlighterPromiseCache.delete(language);
|
||||
|
||||
Reference in new issue
Block a user