perf(web): defer diff workers until a code view opens (#9692)

This commit is contained in:
Theo Browne authored and GitHub committed 2026-09-04 08:15:51 -07:00
1 parent c163d502dd
commit b3e1d88590
11 files changed
+802 -274

No files matched your search

@@ -10,6 +10,7 @@ import {
import type { Ref } from "react";
import { DIFF_SURFACE_THEME_UNSAFE_CSS } from "~/lib/diffRendering";
import { DiffWorkerPoolProvider } from "../DiffWorkerPoolProvider";
const DIFF_VIEW_UNSAFE_CSS = `${DIFF_SURFACE_THEME_UNSAFE_CSS}
:is(
@@ -285,38 +286,40 @@ export function StyledDiffCodeView<LAnnotation = undefined>({
...props
}: StyledDiffCodeViewProps<LAnnotation>) {
return (
<CodeView<LAnnotation>
{...props}
{...(viewerRef ? { ref: viewerRef } : {})}
// The custom element itself is focusable for keyboard scrolling. Its native outline sits
// outside the panel clipping boundary; actual controls inside retain their own indicators.
className={
className
? `diff-render-surface [--code-background:var(--background)] outline-none ${className}`
: "diff-render-surface [--code-background:var(--background)] outline-none"
}
options={{
...options,
unsafeCSS: unsafeCSSExtra
? `${DIFF_VIEW_UNSAFE_CSS}\n${unsafeCSSExtra}`
: DIFF_VIEW_UNSAFE_CSS,
itemMetrics: {
diffHeaderHeight: 32,
hunkSeparatorHeight: 24,
// Pierre uses its general file spacing as a fallback in expanded-file layout paths.
// Keep it zero alongside the explicit paddingTop or expanding the first file can
// reintroduce the library's default 8px gap above its header.
spacing: 0,
paddingTop: 0,
// Unlike the gap above, the 8px under a file's last line is painted
// unconditionally by Pierre's stylesheet (`--diffs-gap-fallback`), so the metric has
// to count it: at zero every expanded file's virtual height ran 8px short of its
// rendered height, and the end of the list sat past the reachable scroll range —
// one clipped file row per expanded file above it.
paddingBottom: 8,
},
layout: { paddingTop: 0, paddingBottom: 0, gap: 0 },
}}
/>
<DiffWorkerPoolProvider>
<CodeView<LAnnotation>
{...props}
{...(viewerRef ? { ref: viewerRef } : {})}
// The custom element itself is focusable for keyboard scrolling. Its native outline sits
// outside the panel clipping boundary; actual controls inside retain their own indicators.
className={
className
? `diff-render-surface [--code-background:var(--background)] outline-none ${className}`
: "diff-render-surface [--code-background:var(--background)] outline-none"
}
options={{
...options,
unsafeCSS: unsafeCSSExtra
? `${DIFF_VIEW_UNSAFE_CSS}\n${unsafeCSSExtra}`
: DIFF_VIEW_UNSAFE_CSS,
itemMetrics: {
diffHeaderHeight: 32,
hunkSeparatorHeight: 24,
// Pierre uses its general file spacing as a fallback in expanded-file layout paths.
// Keep it zero alongside the explicit paddingTop or expanding the first file can
// reintroduce the library's default 8px gap above its header.
spacing: 0,
paddingTop: 0,
// Unlike the gap above, the 8px under a file's last line is painted
// unconditionally by Pierre's stylesheet (`--diffs-gap-fallback`), so the metric has
// to count it: at zero every expanded file's virtual height ran 8px short of its
// rendered height, and the end of the list sat past the reachable scroll range —
// one clipped file row per expanded file above it.
paddingBottom: 8,
},
layout: { paddingTop: 0, paddingBottom: 0, gap: 0 },
}}
/>
</DiffWorkerPoolProvider>
);
}