Skip to content

Commit 4338377

Browse files
t3dotggclaude
andauthored
feat(web): "failed to start" screen helps users recover and report the crash (#25345)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 4e493b1 commit 4338377

3 files changed

Lines changed: 573 additions & 81 deletions

File tree

‎apps/web/index.html‎

Lines changed: 148 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -439,13 +439,23 @@
439439
object-fit: contain;
440440
}
441441

442+
/* App CSS locks body and #root scrolling once main loads, so the error screen scrolls itself. */
443+
#boot-shell:has(> #boot-error) {
444+
height: 100%;
445+
overflow-x: hidden;
446+
overflow-y: auto;
447+
}
448+
442449
#boot-error {
443450
--boot-error-fg: #262626;
444451
--boot-error-bg: #ffffff;
452+
--boot-error-line: color-mix(in srgb, currentColor 12%, transparent);
445453
display: flex;
446454
flex-direction: column;
447455
align-items: flex-start;
456+
align-self: flex-start;
448457
width: min(400px, calc(100% - 48px));
458+
padding: clamp(24px, 22vh, 220px) 0 24px;
449459
font-size: 13px;
450460
line-height: 20px;
451461
}
@@ -469,86 +479,193 @@
469479

470480
#boot-error p {
471481
margin: 4px 0 0;
472-
opacity: 0.6;
482+
opacity: 0.7;
473483
overflow-wrap: anywhere;
474484
text-wrap: pretty;
475485
}
476486

477-
#boot-error code {
487+
#boot-error code,
488+
#boot-error pre {
478489
font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
479490
font-size: 12px;
480491
overflow-wrap: anywhere;
481492
}
482493

494+
#boot-error a {
495+
color: inherit;
496+
text-decoration-line: underline;
497+
text-decoration-color: color-mix(in srgb, currentColor 40%, transparent);
498+
text-underline-offset: 3px;
499+
}
500+
501+
#boot-error a:hover {
502+
text-decoration-color: currentColor;
503+
}
504+
483505
#boot-error button {
484-
border: 0;
506+
height: 32px;
507+
padding: 0 14px;
508+
border: 1px solid var(--boot-error-line);
509+
border-radius: 6px;
510+
background: transparent;
511+
color: inherit;
485512
font: inherit;
513+
font-weight: 500;
486514
cursor: pointer;
487515
}
488516

489-
#boot-error button:focus-visible {
517+
#boot-error button[aria-disabled="true"] {
518+
opacity: 0.6;
519+
cursor: default;
520+
}
521+
522+
#boot-error :is(button, a, summary, pre):focus-visible {
490523
outline: 2px solid var(--boot-error-fg);
491524
outline-offset: 2px;
492525
}
493526

527+
#boot-error-actions {
528+
display: flex;
529+
flex-wrap: wrap;
530+
gap: 8px;
531+
margin-top: 16px;
532+
}
533+
534+
#boot-error #boot-error-reload {
535+
border-color: var(--boot-error-fg);
536+
background: var(--boot-error-fg);
537+
color: var(--boot-error-bg);
538+
}
539+
540+
#boot-error-reload:hover {
541+
opacity: 0.9;
542+
}
543+
544+
#boot-error #boot-error-update-note {
545+
margin-top: 8px;
546+
font-size: 12px;
547+
line-height: 18px;
548+
}
549+
550+
#boot-error details {
551+
width: 100%;
552+
margin-top: 32px;
553+
}
554+
555+
#boot-error summary {
556+
display: inline-flex;
557+
align-items: center;
558+
gap: 8px;
559+
border-radius: 4px;
560+
list-style: none;
561+
opacity: 0.7;
562+
cursor: pointer;
563+
}
564+
565+
#boot-error summary::-webkit-details-marker {
566+
display: none;
567+
}
568+
569+
#boot-error summary::before {
570+
content: "";
571+
width: 5px;
572+
height: 5px;
573+
border-right: 1.5px solid currentColor;
574+
border-bottom: 1.5px solid currentColor;
575+
transform: rotate(-45deg);
576+
}
577+
578+
#boot-error details[open] summary::before {
579+
transform: rotate(45deg);
580+
}
581+
582+
#boot-error summary:hover,
583+
#boot-error details[open] summary {
584+
opacity: 1;
585+
}
586+
587+
#boot-error details > :not(summary) {
588+
display: grid;
589+
gap: 8px;
590+
margin-top: 20px;
591+
}
592+
593+
#boot-error details > a {
594+
display: block;
595+
width: fit-content;
596+
}
597+
598+
#boot-error details p {
599+
margin: 0;
600+
font-size: 12px;
601+
line-height: 18px;
602+
}
603+
494604
#boot-error-command {
495605
display: flex;
496606
align-items: center;
497607
gap: 8px;
498-
box-sizing: border-box;
499-
width: 100%;
500608
padding: 4px 4px 4px 10px;
501-
border: 1px solid color-mix(in srgb, currentColor 10%, transparent);
609+
border: 1px solid var(--boot-error-line);
502610
border-radius: 6px;
503611
}
504612

505613
#boot-error-command code {
506614
flex: 1;
507615
min-width: 0;
508616
opacity: 0.8;
509-
user-select: all;
510617
}
511618

512-
#boot-error-copy {
619+
#boot-error .boot-error-icon {
513620
display: grid;
514621
flex: none;
515622
place-items: center;
516-
width: 24px;
623+
min-width: 24px;
517624
height: 24px;
625+
padding: 0 4px;
626+
border: 0;
518627
border-radius: 4px;
519-
background: transparent;
520-
color: inherit;
521-
opacity: 0.6;
628+
font-size: 12px;
629+
font-weight: 400;
630+
opacity: 0.7;
522631
}
523632

524-
#boot-error-copy:hover {
633+
#boot-error .boot-error-icon:hover {
525634
opacity: 1;
526635
background: color-mix(in srgb, currentColor 8%, transparent);
527636
}
528637

529-
#boot-error-triage {
530-
width: 100%;
531-
margin-top: 40px;
638+
#boot-error-details {
639+
max-height: 200px;
640+
margin: 0;
641+
padding: 10px 12px;
642+
overflow: auto;
643+
border: 1px solid var(--boot-error-line);
644+
border-radius: 6px;
645+
font-size: 11px;
646+
line-height: 16px;
647+
white-space: pre-wrap;
648+
opacity: 0.8;
532649
}
533650

534-
#boot-error-triage p {
535-
margin: 0 0 8px;
536-
font-size: 12px;
537-
line-height: 18px;
651+
#boot-error-report {
652+
display: flex;
653+
align-items: center;
654+
gap: 16px;
538655
}
539656

540-
#boot-error-reload {
541-
height: 32px;
542-
margin-top: 16px;
543-
padding: 0 14px;
544-
border-radius: 6px;
545-
background: var(--boot-error-fg);
546-
color: var(--boot-error-bg);
547-
font-weight: 500;
657+
#boot-error-report button {
658+
height: 28px;
659+
padding: 0 10px;
548660
}
549661

550-
#boot-error-reload:hover {
551-
opacity: 0.9;
662+
.boot-error-sr {
663+
position: absolute;
664+
width: 1px;
665+
height: 1px;
666+
overflow: hidden;
667+
clip-path: inset(50%);
668+
white-space: nowrap;
552669
}
553670
</style>
554671
<title>T3 Code (Beta)</title>

‎apps/web/src/lib/bootError.test.ts‎

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
import type { DesktopBridge, DesktopCliCommandState } from "@t3tools/contracts";
1+
import type { DesktopBridge, DesktopCliCommandState, DesktopUpdateState } from "@t3tools/contracts";
22
import { describe, expect, it, vi } from "vite-plus/test";
33

4-
import { resolveTriageCommand } from "./bootError";
4+
import {
5+
type BootErrorEnvironment,
6+
buildErrorReport,
7+
resolveTriageCommand,
8+
updateActionFor,
9+
} from "./bootError";
510

611
const desktopWith = (getState: () => Promise<DesktopCliCommandState>) =>
712
({ cliCommand: { getState } }) as unknown as DesktopBridge;
@@ -52,3 +57,77 @@ describe("resolveTriageCommand", () => {
5257
).resolves.toBe("npx t3 triage");
5358
});
5459
});
60+
61+
const environment: BootErrorEnvironment = {
62+
version: "0.1.3-nightly.20261026.3707",
63+
channel: "nightly",
64+
surface: "web",
65+
platform: "MacIntel",
66+
userAgent: "Test",
67+
time: "2026-10-26T00:00:00.000Z",
68+
};
69+
70+
describe("buildErrorReport", () => {
71+
it("drops hosts and tokens from URLs in the error", () => {
72+
const error = new TypeError(
73+
"Failed to fetch dynamically imported module: http://studio.tail1234.ts.net:3773/assets/a.js?pair=SECRET#token=SECRET",
74+
{
75+
cause: new Error(
76+
"ws://studio.tail1234.ts.net:3773/ws?token=SECRET closed, main-a.js?sig=SECRET",
77+
),
78+
},
79+
);
80+
error.stack = `TypeError: ${error.message}\n at http://studio.tail1234.ts.net:3773/src/main.tsx?t=1:10:5`;
81+
const report = buildErrorReport(error, environment);
82+
expect(report).not.toContain("SECRET");
83+
expect(report).not.toContain("tail1234");
84+
expect(report).toContain("module: /assets/a.js\n at /src/main.tsx:10:5");
85+
expect(report).toContain("Caused by: Error: /ws closed, main-a.js");
86+
expect(report).toContain("Version: 0.1.3-nightly.20261026.3707");
87+
});
88+
89+
it("keeps the header when a Firefox stack frame starts with the error name", () => {
90+
const error = new Error("boot failed");
91+
error.stack = "ErrorBoundary@/assets/main.js:1:2";
92+
expect(buildErrorReport(error, environment)).toMatch(
93+
/^Error: boot failed\nErrorBoundary@\/assets\/main.js:1:2\n/,
94+
);
95+
const unnamed = new Error();
96+
unnamed.stack = "ErrorBoundary@/assets/main.js:1:2";
97+
expect(buildErrorReport(unnamed, environment)).toMatch(/^Error\nErrorBoundary@/);
98+
});
99+
100+
it("stops at cause cycles and survives values that are not errors", () => {
101+
const loop = new Error("outer");
102+
loop.cause = loop;
103+
expect(buildErrorReport(loop, environment).match(/outer/g)).toHaveLength(1);
104+
expect(buildErrorReport("plain text", environment)).toMatch(/^plain text\n/);
105+
expect(buildErrorReport({ code: 42 }, environment)).toMatch(/^\{"code":42\}\n/);
106+
expect(buildErrorReport(Object.create(null), environment)).toMatch(/^\{\}\n/);
107+
expect(buildErrorReport(undefined, environment)).toMatch(/^\(no error message\)\n/);
108+
});
109+
110+
it("cuts long errors but keeps the environment", () => {
111+
const report = buildErrorReport("x".repeat(20_000), environment);
112+
expect(report).toContain("[truncated]");
113+
expect(report.length).toBeLessThan(7_000);
114+
expect(report).toContain("Time: 2026-10-26T00:00:00.000Z");
115+
});
116+
});
117+
118+
describe("updateActionFor", () => {
119+
it("offers an action only when a newer build exists", () => {
120+
const state = (status: DesktopUpdateState["status"], downloadPercent: number | null = null) =>
121+
({ status, downloadPercent }) as DesktopUpdateState;
122+
expect(updateActionFor(state("available"))).toEqual({ kind: "download" });
123+
expect(updateActionFor(state("downloading", 41.6))).toEqual({
124+
kind: "downloading",
125+
percent: 42,
126+
});
127+
expect(updateActionFor(state("downloaded"))).toEqual({ kind: "install" });
128+
for (const status of ["disabled", "idle", "checking", "up-to-date", "error"] as const) {
129+
expect(updateActionFor(state(status))).toBeNull();
130+
}
131+
expect(updateActionFor(undefined)).toBeNull();
132+
});
133+
});

0 commit comments

Comments
 (0)