From 6ea388a20612adf5f75458521cb089a7bddbaa51 Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+Hona@users.noreply.github.com> Date: Wed, 2 Sep 2026 20:12:20 +1000 Subject: [PATCH] fix(session-ui): render large diffs as plain text in the worker pool (#46772) --- .../performance/highlighting/README.md | 5 +++-- .../highlighting/plain.correctness.ts | 19 +++++++++++++++++++ packages/session-ui/src/pierre/worker.ts | 3 +++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 packages/session-ui/performance/highlighting/plain.correctness.ts diff --git a/packages/session-ui/performance/highlighting/README.md b/packages/session-ui/performance/highlighting/README.md index 06eec60ffa3..510a97d8e8c 100644 --- a/packages/session-ui/performance/highlighting/README.md +++ b/packages/session-ui/performance/highlighting/README.md @@ -25,8 +25,9 @@ mechanism, not CPU time or desktop memory. Full reconstructed content is checked separately after timing. No forced GC or machine-dependent thresholds are used. `HIGHLIGHT_CORRECTNESS=1` runs the deterministic `*.correctness.ts` checks against -the same fixture instead of the timed benchmarks: cache reuse across remounts and -invalidation on content, theme, and worker option changes. +the same fixture instead of the timed benchmarks: cache reuse across remounts, +invalidation on content, theme, and worker option changes, and plain rendering of +large diffs with complete reconstructed content. Optional output settings: `HIGHLIGHT_RESULTS`, `HIGHLIGHT_SCREENSHOTS`, `OPENCODE_PERFORMANCE_RUN_ID`, and `OPENCODE_PERFORMANCE_TRACE_DIR` (separate diff --git a/packages/session-ui/performance/highlighting/plain.correctness.ts b/packages/session-ui/performance/highlighting/plain.correctness.ts new file mode 100644 index 00000000000..f7d27082282 --- /dev/null +++ b/packages/session-ui/performance/highlighting/plain.correctness.ts @@ -0,0 +1,19 @@ +import { expect, test } from "@playwright/test" +import type {} from "./viewer" + +test("renders large diffs as plain text without changing ordinary highlighting", async ({ page }) => { + await page.goto("/?large") + await page.waitForFunction(() => !!window.highlighting) + const large = await page.evaluate(() => window.highlighting.mount(1)) + expect(large.options).toMatchObject({ lineDiffType: "none", maxLineDiffLength: 0, tokenizeMaxLineLength: 1 }) + expect(large.syntaxSpans).toBe(0) + await expect(page.locator('[data-line="11"][data-line-type="change-addition"]')).toContainText("status: 201") + expect(await page.evaluate(() => window.highlighting.contents()!.after === window.highlighting.input.after[0])).toBe(true) + + await page.goto("/") + await page.waitForFunction(() => !!window.highlighting) + const ordinary = await page.evaluate(() => window.highlighting.mount(1)) + expect(ordinary.options).toMatchObject({ lineDiffType: "word-alt", maxLineDiffLength: 1000, tokenizeMaxLineLength: 1000 }) + expect(ordinary.syntaxSpans).toBeGreaterThan(0) + await expect(page.locator('[data-line="11"][data-line-type="change-addition"]')).toContainText("status: 201") +}) diff --git a/packages/session-ui/src/pierre/worker.ts b/packages/session-ui/src/pierre/worker.ts index d092dae43e7..ba5d30dccc1 100644 --- a/packages/session-ui/src/pierre/worker.ts +++ b/packages/session-ui/src/pierre/worker.ts @@ -22,6 +22,9 @@ function createPool(lineDiffType: "none" | "word-alt") { { theme: "OpenCode", lineDiffType, + // Pierre renders with the pool's options, not the viewer's, whenever the pool works. The "none" pool only + // serves diffs above the large-file threshold, so it carries the plain-text fallback the viewer requests. + ...(lineDiffType === "none" && { maxLineDiffLength: 0, tokenizeMaxLineLength: 1 }), preferredHighlighter: "shiki-wasm", }, )