authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-06-20 11:02:07-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-06-20 11:02:07-07:00
log08650a7424f0f4d28c36d50938c0027e5b4cafff
tree7d9917e991148ad8af8026d0e807de95904112ed
parent40d14647db0adfcb66b1bfe4482868c425c3c5d8
signature Signed by PGP key B5690EEEBB952194

[codex] Structure web diff worker failures (#3356)

Co-authored-by: codex <codex@users.noreply.github.com>

1 files changed, 38 insertions(+), 11 deletions(-)

apps/web/src/components/DiffWorkerPoolProvider.tsx+38-11
...@@ -1,9 +1,20 @@...@@ -1,9 +1,20 @@
1import { WorkerPoolContextProvider, useWorkerPool } from "@pierre/diffs/react";1import { WorkerPoolContextProvider, useWorkerPool } from "@pierre/diffs/react";
2import DiffsWorker from "@pierre/diffs/worker/worker.js?worker";2import DiffsWorker from "@pierre/diffs/worker/worker.js?worker";
3import * as Schema from "effect/Schema";
3import { useEffect, useMemo, type ReactNode } from "react";4import { useEffect, useMemo, type ReactNode } from "react";
4import { useTheme } from "../hooks/useTheme";5import { useTheme } from "../hooks/useTheme";
5import { resolveDiffThemeName, type DiffThemeName } from "../lib/diffRendering";6import { resolveDiffThemeName, type DiffThemeName } from "../lib/diffRendering";
67
8export class DiffWorkerError extends Schema.TaggedErrorClass<DiffWorkerError>()("DiffWorkerError", {
9 operation: Schema.Literals(["create-worker", "get-render-options", "set-render-options"]),
10 themeName: Schema.Literals(["pierre-light", "pierre-dark"]),
11 cause: Schema.Defect(),
12}) {
13 override get message(): string {
14 return `Diff worker operation ${this.operation} failed for theme ${this.themeName}.`;
15 }
16}
17
7function DiffWorkerThemeSync({ themeName }: { themeName: DiffThemeName }) {18function DiffWorkerThemeSync({ themeName }: { themeName: DiffThemeName }) {
8 const workerPool = useWorkerPool();19 const workerPool = useWorkerPool();
920
...@@ -12,17 +23,23 @@ function DiffWorkerThemeSync({ themeName }: { themeName: DiffThemeName }) {...@@ -12,17 +23,23 @@ function DiffWorkerThemeSync({ themeName }: { themeName: DiffThemeName }) {
12 return;23 return;
13 }24 }
1425
15 const current = workerPool.getDiffRenderOptions();26 let operation: DiffWorkerError["operation"] = "get-render-options";
16 if (current.theme === themeName) {27 void (async () => {
17 return;28 try {
18 }29 const current = workerPool.getDiffRenderOptions();
30 if (current.theme === themeName) {
31 return;
32 }
1933
20 void workerPool34 operation = "set-render-options";
21 .setRenderOptions({35 await workerPool.setRenderOptions({
22 ...current,36 ...current,
23 theme: themeName,37 theme: themeName,
24 })38 });
25 .catch(() => undefined);39 } catch (cause) {
40 console.error(new DiffWorkerError({ operation, themeName, cause }));
41 }
42 })();
26 }, [themeName, workerPool]);43 }, [themeName, workerPool]);
2744
28 return null;45 return null;
...@@ -40,7 +57,17 @@ export function DiffWorkerPoolProvider({ children }: { children?: ReactNode }) {...@@ -40,7 +57,17 @@ export function DiffWorkerPoolProvider({ children }: { children?: ReactNode }) {
40 return (57 return (
41 <WorkerPoolContextProvider58 <WorkerPoolContextProvider
42 poolOptions={{59 poolOptions={{
43 workerFactory: () => new DiffsWorker(),60 workerFactory: () => {
61 try {
62 return new DiffsWorker();
63 } catch (cause) {
64 throw new DiffWorkerError({
65 operation: "create-worker",
66 themeName: diffThemeName,
67 cause,
68 });
69 }
70 },
44 poolSize: workerPoolSize,71 poolSize: workerPoolSize,
45 totalASTLRUCacheSize: 240,72 totalASTLRUCacheSize: 240,
46 }}73 }}