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 @@
11import { WorkerPoolContextProvider, useWorkerPool } from "@pierre/diffs/react";
22import DiffsWorker from "@pierre/diffs/worker/worker.js?worker";
3import * as Schema from "effect/Schema";
34import { useEffect, useMemo, type ReactNode } from "react";
45import { useTheme } from "../hooks/useTheme";
56import { 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
718function DiffWorkerThemeSync({ themeName }: { themeName: DiffThemeName }) {
819 const workerPool = useWorkerPool();
920
......@@ -12,17 +23,23 @@ function DiffWorkerThemeSync({ themeName }: { themeName: DiffThemeName }) {
1223 return;
1324 }
1425
15 const current = workerPool.getDiffRenderOptions();
16 if (current.theme === themeName) {
17 return;
18 }
26 let operation: DiffWorkerError["operation"] = "get-render-options";
27 void (async () => {
28 try {
29 const current = workerPool.getDiffRenderOptions();
30 if (current.theme === themeName) {
31 return;
32 }
1933
20 void workerPool
21 .setRenderOptions({
22 ...current,
23 theme: themeName,
24 })
25 .catch(() => undefined);
34 operation = "set-render-options";
35 await workerPool.setRenderOptions({
36 ...current,
37 theme: themeName,
38 });
39 } catch (cause) {
40 console.error(new DiffWorkerError({ operation, themeName, cause }));
41 }
42 })();
2643 }, [themeName, workerPool]);
2744
2845 return null;
......@@ -40,7 +57,17 @@ export function DiffWorkerPoolProvider({ children }: { children?: ReactNode }) {
4057 return (
4158 <WorkerPoolContextProvider
4259 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 },
4471 poolSize: workerPoolSize,
4572 totalASTLRUCacheSize: 240,
4673 }}