fix(build): 부팅 실패 화면이 앱 그래프 청크 없이 그려진다
앱 모듈 하나가 평가 중에 예외를 던지면 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에서 통과한다.
This commit is contained in:
@@ -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<string>();
|
||||
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);
|
||||
|
||||
+35
-19
@@ -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,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user