Skip to content
TypeScript

ci(web): releases fail when the built web app cannot boot (#25929)

Theo Browne30f4d6374a0f
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 8e389b52454..bc3b79002cb 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -344,6 +344,12 @@ jobs:
- name: Test
run: vp run --filter @t3tools/web test
+ # Browser tests run source modules; this boots the production chunk graph.
+ - name: Boot the built web client
+ run: |
+ vp run --filter @t3tools/web build
+ node apps/web/scripts/verify-built-boot.ts
+
# apps/server sets `fileParallelism: false`, so its test files run strictly
# one at a time. Sharding spreads them over separate runners instead of
# separate workers, so no two server test files ever share a machine and the
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index d1045a239c8..422dee70624 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -344,6 +344,12 @@ jobs:
- name: Test
run: vp run --filter @t3tools/web test
+ # Browser tests run source modules; this boots the production chunk graph.
+ - name: Boot the built web client
+ run: |
+ vp run --filter @t3tools/web build
+ node apps/web/scripts/verify-built-boot.ts
+
# Server test files run one at a time, so more small runners beat fewer big ones.
test_server:
name: Release server tests ${{ matrix.shard }}
diff --git a/apps/web/scripts/verify-built-boot.ts b/apps/web/scripts/verify-built-boot.ts
new file mode 100644
index 00000000000..3d9ffc37b27
--- /dev/null
+++ b/apps/web/scripts/verify-built-boot.ts
@@ -0,0 +1,57 @@
+// @effect-diagnostics nodeBuiltinImport:off - plain Node script CI runs against the built client.
+// Boots the built web client in headless Chromium and fails if it reaches showBootError.
+// Source-level browser tests never run the production chunk graph, where boot breaks hide.
+import * as NodeFS from "node:fs";
+import * as NodePath from "node:path";
+import * as NodeURL from "node:url";
+import { chromium } from "playwright";
+
+const distDir = NodeURL.fileURLToPath(new URL("../dist/", import.meta.url));
+const origin = "http://t3-boot.test";
+// With no server, the client retries its session for about 15s before it renders.
+const timeoutMs = 60_000;
+
+if (!NodeFS.existsSync(NodePath.join(distDir, "index.html"))) {
+ console.error(`No web build at ${distDir}. Run the web build first.`);
+ process.exit(1);
+}
+
+const browser = await chromium.launch();
+try {
+ const page = await browser.newPage();
+ const errors: string[] = [];
+ page.on("pageerror", (error) => errors.push(error.stack ?? error.message));
+ page.on("console", (message) => {
+ if (message.type() === "error") errors.push(message.text());
+ });
+
+ // Serve dist with an SPA fallback; the client has no server here, so other requests fail fast.
+ await page.route("**/*", (route) => {
+ const url = new URL(route.request().url());
+ if (url.origin !== origin) return route.abort();
+ const file = NodePath.join(distDir, decodeURIComponent(url.pathname));
+ const isAsset =
+ file.startsWith(distDir) && NodeFS.statSync(file, { throwIfNoEntry: false })?.isFile();
+ if (isAsset) return route.fulfill({ path: file });
+ if (url.pathname.startsWith("/api/") || url.pathname.startsWith("/.well-known/")) {
+ return route.fulfill({ status: 503 });
+ }
+ return route.fulfill({ path: NodePath.join(distDir, "index.html") });
+ });
+
+ await page.goto(`${origin}/`);
+ // React replaces the static #boot-shell splash when it mounts; showBootError fills it instead.
+ const settled = await page.waitForSelector("#root > :not(#boot-shell), #boot-error-reload", {
+ timeout: timeoutMs,
+ });
+
+ if (await settled.evaluate((node) => node.id === "boot-error-reload")) {
+ console.error("The built web client failed to boot:");
+ for (const error of errors) console.error(error);
+ process.exitCode = 1;
+ } else {
+ console.log("The built web client booted and mounted React.");
+ }
+} finally {
+ await browser.close();
+}
diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json
index e7bf2b0d7af..b9cd3ad6b5e 100644
--- a/apps/web/tsconfig.json
+++ b/apps/web/tsconfig.json
@@ -31,6 +31,7 @@
"vite.config.ts",
"vercel.ts",
"test",
+ "scripts/verify-built-boot.ts",
"scripts/warm-dep-cache.ts",
"../../scripts/lib/public-config.ts",
"../../scripts/lib/third-party-licenses.ts"