@devries-cameron20 / t3code Mirror · read-only / commits / 08650a7424
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 24, 22:45 UTC

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

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

Julius Marminge committed Jun 20, 2026 at 11:02 UTC 08650a7424f0f4d28c36d50938c0027e5b4cafff
1 file changed +38 -11
apps/web/src/components/DiffWorkerPoolProvider.tsx
+38 -11
@@ -1,9 +1,20 @@
1 import { WorkerPoolContextProvider, useWorkerPool } from "@pierre/diffs/react";
2 import DiffsWorker from "@pierre/diffs/worker/worker.js?worker";
3 +import * as Schema from "effect/Schema";
4 import { useEffect, useMemo, type ReactNode } from "react";
5 import { useTheme } from "../hooks/useTheme";
6 import { resolveDiffThemeName, type DiffThemeName } from "../lib/diffRendering";
7
8 +export 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 +
18 function DiffWorkerThemeSync({ themeName }: { themeName: DiffThemeName }) {
19 const workerPool = useWorkerPool();
20
@@ -12,17 +23,23 @@ function DiffWorkerThemeSync({ themeName }: { themeName: DiffThemeName }) {
23 return;
24 }
25
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 + }
33
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 + })();
43 }, [themeName, workerPool]);
44
45 return null;
@@ -40,7 +57,17 @@ export function DiffWorkerPoolProvider({ children }: { children?: ReactNode }) {
57 return (
58 <WorkerPoolContextProvider
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 + },
71 poolSize: workerPoolSize,
72 totalASTLRUCacheSize: 240,
73 }}