diff --git a/tests/unit/build-environment-bundle.test.ts b/tests/unit/build-environment-bundle.test.ts index 848b957..d8ce187 100644 --- a/tests/unit/build-environment-bundle.test.ts +++ b/tests/unit/build-environment-bundle.test.ts @@ -94,6 +94,39 @@ describe("build variables in the bundle (13-06)", () => { expect(reactDom(second)).toEqual(reactDom(first)); }, 120_000); + // 09-03. main.tsx imports the boot-failure screen when the application + // graph throws while its modules evaluate, so that screen must not import a + // chunk holding that graph. installed-feature-messages.ts (the module the + // boot-module-failure e2e makes throw) is found by its error text. + it("draws the boot-failure screen without the application graph", async () => { + const { run, contents } = await build({ VITE_BUILD_ID: "build-probe-boot" }); + expect(run.status).toBe(0); + const chunks = new Map( + contents + .filter(({ file }) => file.endsWith(".js")) + .map(({ file, text }) => [path.basename(file), text]), + ); + const staticImports = (text: string) => + [...text.matchAll(/(?:from|import)\s*"\.\/([\w.-]+\.js)"/gu)].map( + ([, name]) => name!, + ); + const entry = [...chunks.keys()].find((name) => + name.startsWith("render-boot-failure-"), + ); + expect(entry).toBeDefined(); + const reached = new Set(); + const pending = [entry!]; + while (pending.length > 0) { + const name = pending.pop()!; + if (reached.has(name)) continue; + reached.add(name); + pending.push(...staticImports(chunks.get(name) ?? "")); + } + expect( + [...reached].filter((name) => chunks.get(name)?.includes("message key: ")), + ).toEqual([]); + }, 120_000); + it("refuses a VITE_* variable the build does not declare", async () => { const refused = await build({ VITE_PAYMENT_KEY: "sk_live_probe" }); expect(refused.run.status).not.toBe(0); diff --git a/vite.config.ts b/vite.config.ts index ef99e85..6000eeb 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -135,27 +135,43 @@ export default defineConfig(({ mode }) => { resolveDependencies: (_filename, deps) => deps.filter((dep) => !dep.includes("route-tech-log-studio")), }, - // Template sync (af3d8e6). One chunking function under the key this - // product already builds with: the template's preload-helper split - // (09-03) first, then TechLog's named route chunks. + // Template sync (af3d8e6): the template's chunk groups, then TechLog's + // named route chunks, in the template's `codeSplitting` form. rolldownOptions: { output: { - // 09-03. The entry now imports the app dynamically, so Vite's preload - // helper would land in the entry chunk and every lazy chunk would - // import the entry, whose hash changes with each build id. - // - // Template 1103/15-06 (af6d0a9f). react-dom and scheduler shared the - // boot-failure chunk with the build id (getBuildConfig), so a release - // that only changed the build id renamed that 190 KB chunk and - // returning visitors downloaded it again. In a chunk of their own they - // keep their name; only boot, the entry and the small boot-failure - // screen, which hold or import the build id, are renamed. - manualChunks: (id: string) => - id.includes("vite/preload-helper") - ? "preload-helper" - : REACT_DOM_MODULE.test(id) - ? "react-dom" - : routeChunkName(id), + codeSplitting: { + groups: [ + // 09-03. The entry now imports the app dynamically, so Vite's + // preload helper would land in the entry chunk and every lazy + // chunk would import the entry, whose hash changes with each + // build id. + { name: "preload-helper", test: /vite[\\/]preload-helper/ }, + // Template 1103/15-06 (af6d0a9f). react-dom and scheduler shared + // the boot-failure chunk with the build id (getBuildConfig), so a + // release that only changed the build id renamed that 190 KB + // chunk and returning visitors downloaded it again. In a chunk of + // their own they keep their name; only boot, the entry and the + // small boot-failure screen, which hold or import the build id, + // are renamed. + { + name: "react-dom", + test: REACT_DOM_MODULE, + includeDependenciesRecursively: false, + }, + // A route page gets its named chunk, its imports do not. The + // `manualChunks` function this replaces is a group that pulls + // every static dependency in: `route-not-found` took React, the + // i18n catalogs and installed-feature-messages.ts with it, and + // the boot-failure screen imports from that chunk. A module that + // threw while the application graph evaluated then took the + // boot-failure screen down too, and the static "loading" shell + // stayed up (boot-module-failure e2e, 09-03). + { + name: (id: string) => routeChunkName(id) ?? null, + includeDependenciesRecursively: false, + }, + ], + }, }, }, },