From 9e20d471b0276442bc264066f678401852e78aef Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 12 Nov 2026 16:02:59 +0900 Subject: [PATCH] =?UTF-8?q?fix(build):=20=EB=B6=80=ED=8C=85=20=EC=8B=A4?= =?UTF-8?q?=ED=8C=A8=20=ED=99=94=EB=A9=B4=EC=9D=B4=20=EC=95=B1=20=EA=B7=B8?= =?UTF-8?q?=EB=9E=98=ED=94=84=20=EC=B2=AD=ED=81=AC=20=EC=97=86=EC=9D=B4=20?= =?UTF-8?q?=EA=B7=B8=EB=A0=A4=EC=A7=84=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 앱 모듈 하나가 평가 중에 예외를 던지면 main.tsx는 부팅 실패 화면 (render-boot-failure.tsx)을 그린다. 그런데 그 청크가 route-not-found 청크에서 값 둘을 import하고, route-not-found에는 React, i18n 카탈로그, installed-feature-messages.ts가 같이 들어 있다. 그래서 예외를 던진 청크에 실패 화면도 같이 걸려 그리지 못하고, 정적 「불러오는 중」 화면이 계속 남는다(boot-module-failure e2e, 세 엔진 모두). 원인은 vite.config.ts의 manualChunks다. Rolldown은 manualChunks를 includeDependenciesRecursively가 기본값(true)인 group으로 바꾼다. 그래서 route-not-found로 지정한 Public not-found 화면이 자기 정적 의존을 전부 그 청크로 끌고 간다. PR #6 전(27e342d) 빌드도 같은 import가 있었다. 템플릿과 같은 output.codeSplitting.groups 형식으로 바꾼다. react-dom과 route 화면 group은 includeDependenciesRecursively: false로 둬서, 화면 모듈만 그 이름의 청크에 들어가게 한다. 공유 모듈은 Rolldown이 쓰는 쪽에 따라 나눈다. preload-helper·react-dom·route 청크 이름은 그대로다. 검증: - build-environment-bundle.test.ts에 시험 하나를 더했다. 실패 화면 청크에서 정적 import로 닿는 청크 가운데 installed-feature-messages의 오류 문구가 든 것이 없어야 한다. 고치기 전에는 route-not-found-*.js가 잡혀 실패했고, 고친 뒤 통과한다. - vite-route-chunks, bundle-*, chunk-recovery*, performance-budgets 단위 시험(29건) 통과. - e2e: boot-module-failure, old-tab-chunk-recovery, service-worker-update·recovery, production-csp가 chromium·firefox· webkit에서 통과한다. --- tests/unit/build-environment-bundle.test.ts | 33 +++++++++++++ vite.config.ts | 54 +++++++++++++-------- 2 files changed, 68 insertions(+), 19 deletions(-) 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, + }, + ], + }, }, }, },