@devries-cameron20 / t3code Mirror · read-only / commits / 2755a951a1
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 21, 18:30 UTC

fix(web): "Try again" recovers from a failed page chunk load (#35806)

Julius Marminge committed Nov 12, 2026 at 18:39 UTC 2755a951a18b7b1725cf165718d014c3b7261245
3 files changed +33 -2
apps/web/src/lib/chunkReloadGuard.test.ts
+12 -1
@@ -1,6 +1,6 @@
1 import { describe, expect, it, vi } from "vite-plus/test";
2
3 -import { reloadOnceForChunkLoadError } from "./chunkReloadGuard";
3 +import { isChunkLoadError, reloadOnceForChunkLoadError } from "./chunkReloadGuard";
4
5 function createStorageStub(): Storage {
6 const store = new Map<string, string>();
@@ -52,3 +52,14 @@ describe("reloadOnceForChunkLoadError", () => {
52 expect(reload).not.toHaveBeenCalled();
53 });
54 });
55 +
56 +describe("isChunkLoadError", () => {
57 + it.each([
58 + ["Failed to fetch dynamically imported module: t3code://app/assets/a.js", true],
59 + ["error loading dynamically imported module: https://app.t3.codes/assets/a.js", true],
60 + ["Importing a module script failed.", true],
61 + ["Cannot read properties of undefined", false],
62 + ])("%s", (message, expected) => {
63 + expect(isChunkLoadError(new TypeError(message))).toBe(expected);
64 + });
65 +});
apps/web/src/lib/chunkReloadGuard.ts
+14
@@ -20,3 +20,17 @@ export function reloadOnceForChunkLoadError(
20 reload();
21 return true;
22 }
23 +
24 +// Browsers cache a failed dynamic import per document, so only a reload can retry it.
25 +const CHUNK_LOAD_ERROR_PREFIXES = [
26 + "Failed to fetch dynamically imported module", // Chromium
27 + "error loading dynamically imported module", // Firefox
28 + "Importing a module script failed", // Safari
29 +];
30 +
31 +export function isChunkLoadError(error: unknown): boolean {
32 + const message = error instanceof Error ? error.message : undefined;
33 + return (
34 + message !== undefined && CHUNK_LOAD_ERROR_PREFIXES.some((prefix) => message.startsWith(prefix))
35 + );
36 +}
apps/web/src/routes/__root.tsx
+7 -1
@@ -57,6 +57,7 @@ import { primaryServerConfigAtom, primaryServerWelcomeAtom } from "../state/serv
57 import { readProject } from "../state/entities";
58
59 import { getDesktopSnapShotBridge } from "../lib/desktopSnapShot";
60 +import { isChunkLoadError } from "../lib/chunkReloadGuard";
61 import { shouldResumeSnapShotSetupOnStartup } from "../lib/snapShotSetupResume";
62
63 export const Route = createRootRoute({
@@ -243,7 +244,12 @@ function RootRouteErrorView({ error }: ErrorComponentProps) {
244 <StandalonePageHeader title="Something went wrong." description={message} />
245
246 <div className="mt-5 flex flex-wrap gap-2">
246 - <Button size="sm" onClick={() => void router.invalidate()}>
247 + <Button
248 + size="sm"
249 + onClick={() =>
250 + isChunkLoadError(error) ? window.location.reload() : void router.invalidate()
251 + }
252 + >
253 Try again
254 </Button>
255 <Button size="sm" variant="outline" onClick={() => window.location.reload()}>