From 267c72459eef4c7d13fa81c29348c0fb5a8012fd Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Tue, 3 Nov 2026 20:47:03 +0900 Subject: [PATCH] =?UTF-8?q?test(e2e):=20=EB=B9=A0=EC=A7=84=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=99=80=20=EA=B0=99=EC=9D=B4=20preload?= =?UTF-8?q?=ED=95=9C=20=EC=B2=AD=ED=81=AC=EC=9D=98=20WebKit=20=EA=B2=BD?= =?UTF-8?q?=EA=B3=A0=EB=A5=BC=20=ED=97=88=EC=9A=A9=ED=95=9C=EB=8B=A4=20(11?= =?UTF-8?q?01/14.3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제 webkit에서 old-tab-chunk-recovery.spec.ts가 가끔 실패한다. WebKit은 문서의 load 이벤트 3초 뒤에 한 번, 아직 쓰지 않은 link preload마다 경고를 남기고 strict console 검사가 그 경고를 실패로 본다. - A 탭에서 B를 배포하고 플랫폼 화면을 누르면, Vite preload helper가 페이지 청크와 그 청크가 import하는 badge·card·schema-registry·server-state를 같이 preload한다. 페이지 청크가 404라 import가 실패하고, 같이 받은 청크는 끝까지 쓰이지 않는다. 복구가 release manifest를 읽는 동안 A 문서가 load+3초를 넘기면 경고 4줄이 나온다. B 탭의 UI 화면에서도 같은 일이 생긴다 (text-field). - 그 청크들은 플랫폼 화면이 실제로 import한다(.vite/manifest.json). 앱이 쓰지 않는 청크를 preload하는 것이 아니다. 경고는 테스트가 일부러 지운 청크의 결과다. - 08-08과의 관계: 원인이 아니다. 08-08 전(e1a4580) 빌드에서도 플랫폼 화면은 lazy 청크 schema-registry·server-state를 같이 preload한다. 08-08은 목록에 badge·card를 더했을 뿐이고, 목록이 비어 있지 않으면 같은 경고가 나온다. - 간헐인 이유: 클릭이 load+3초 전에 일어나고 문서가 load+3초 뒤까지 남을 때만 경고가 나온다. 부하가 높을수록 자주 맞는다. 고른 방법 - 이 spec의 허용 목록에 WebKit 경고 문구 하나를 더한다. WebKit에서만, 빠진 두 페이지가 import하는 청크 이름만 허용한다. 이름은 고정하지 않고 각 빌드의 .vite/manifest.json에서 정적 import를 따라가 구한다(A의 플랫폼 화면, B의 UI 화면). 다른 청크의 같은 경고와 다른 브라우저는 그대로 실패한다. 버린 대안 - preload를 끄거나 줄이기(build.modulePreload): 모든 lazy 화면에서 페이지 청크를 받은 뒤 import를 다시 받는 왕복이 하나 는다. 테스트 경고 하나 때문에 세 브라우저의 화면 전환을 느리게 할 이유가 없다. - B 배포 전에 3초 넘게 기다리기: "오래 열린 탭"에는 맞지만 WebKit 내부 상수 (3초)에 묶인 고정 대기이고, 경고를 설명하지 않고 피한다. - strict-browser-test.ts 전역 허용: 다른 spec의 진짜 unused preload까지 덮는다. 위험·한계 - 허용 범위는 manifest에서 구한 청크 목록이다. 실제 preload 목록은 Vite가 만드는 __vite__mapDeps이고, 둘이 갈라지면 경고가 다시 실패로 나온다(덮이지 않는 쪽으로 틀린다). - WebKit 문구가 바뀌면 다시 실패한다. 검증 - RED(ec7435c, webkit, flock, workers 1) - 그대로 30회: 2회 실패(경고 4줄, badge·card·schema-registry·server-state), loadavg 14.8~17. - 시점 고정 재현(scratch spec, 원본 수정 없음): 복구의 manifest 응답을 3.5초 늦추면 3/3 실패(같은 4줄). UI 오류 뒤 3.5초 기다리면 2/2 실패 (text-field 1줄). - GREEN - 시점 고정 재현 두 가지를 고친 spec으로: 6/6 통과. - 그대로 30회: workers 1에서 30/30 통과(loadavg 3.9~8.4), workers 3에서 30/30 통과(loadavg 9.0~18.0, 평균 14). - chromium·firefox: 각 3회 통과. 시점 고정 재현도 두 엔진에서 경고 없이 통과한다(이 경고는 WebKit만 낸다). - webkit e2e 전체(preview 빌드, 11 workers): 63/63 통과(loadavg 5.2~19.9). - npx tsc --project tsconfig.test.json --noEmit, npx eslint (바꾼 파일) 통과. --- tests/e2e/old-tab-chunk-recovery.spec.ts | 68 ++++++++++++++++++------ 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/tests/e2e/old-tab-chunk-recovery.spec.ts b/tests/e2e/old-tab-chunk-recovery.spec.ts index 9ef45f8c..142eed2f 100644 --- a/tests/e2e/old-tab-chunk-recovery.spec.ts +++ b/tests/e2e/old-tab-chunk-recovery.spec.ts @@ -21,10 +21,9 @@ import { startBuildServer } from "./support/service-worker-builds.ts"; const PLATFORM = ROUTE_REGISTRY.EXAMPLES_PLATFORM; const UI = ROUTE_REGISTRY.EXAMPLES_UI; -const PAGES = [ - "src/presentation/examples/platform-overview-page.tsx", - "src/presentation/examples/ui-gallery-page.tsx", -] as const; +const PLATFORM_PAGE = "src/presentation/examples/platform-overview-page.tsx"; +const UI_PAGE = "src/presentation/examples/ui-gallery-page.tsx"; +const PAGES = [PLATFORM_PAGE, UI_PAGE] as const; let builds: FixtureBuilds<"a" | "b"> | undefined; @@ -60,20 +59,57 @@ async function routeChunk(dist: string, chunkId: string): Promise { // Each missing page chunk fails its request and the dynamic import. Chromium // may also log the 404 itself (without its URL), Firefox logs the error // object React caught, and WebKit logs its own import error without the URL. -// Nothing else is allowed. +// Nothing else is allowed, but for the WebKit warning below. const MISSING_PAGE = String.raw`/assets/(?:platform-overview|ui-gallery)-page-[\w-]+\.js`; +const MISSING_PAGE_FAILURES = [ + String.raw`^requestfailed:GET:${MISSING_PAGE}:`, + String.raw`^console:error:TypeError: Failed to fetch dynamically imported module: http://127\.0\.0\.1:\d+${MISSING_PAGE}$`, + String.raw`^console:error:\[JavaScript Error: "Loading module from “http://127\.0\.0\.1:\d+${MISSING_PAGE}” was blocked`, + String.raw`^console:error:Failed to load resource: the server responded with a status of 404 \(Not Found\)$`, + String.raw`^console:error:JSHandle@object$`, + String.raw`^console:error:TypeError: Importing a module script failed\.$`, +]; + +/** The chunks Vite preloads with `page`: its static imports in `dist`. */ +async function preloadedWith(dist: string, page: string): Promise { + const manifest = JSON.parse( + await readFile(path.join(dist, ".vite/manifest.json"), "utf8"), + ) as Record; + if (!manifest[page]) throw new Error(`${page} is not in ${dist}'s manifest.`); + const files = new Set(); + const pending = [...(manifest[page].imports ?? [])]; + for (let key = pending.pop(); key !== undefined; key = pending.pop()) { + const entry = manifest[key]; + if (!entry || files.has(entry.file)) continue; + files.add(entry.file); + pending.push(...(entry.imports ?? [])); + } + return [...files]; +} + +// WebKit only. Three seconds after a document's load event, WebKit warns once +// for each link-preloaded resource the document has not used yet. Vite +// preloads a page chunk together with the chunks it imports, so a missing page +// leaves the chunks preloaded with it unused: in the A tab those of A's +// platform page (the tab is still on A while recovery reads the release +// manifest), in the B tab those of B's UI page. Whether that check runs before +// the reload, or before the test ends, is timing, so the warnings come and go. +// They are the provoked failure's own effect; only those chunks are allowed. test.use({ - allowedBrowserFailure: new RegExp( - [ - String.raw`^requestfailed:GET:${MISSING_PAGE}:`, - String.raw`^console:error:TypeError: Failed to fetch dynamically imported module: http://127\.0\.0\.1:\d+${MISSING_PAGE}$`, - String.raw`^console:error:\[JavaScript Error: "Loading module from “http://127\.0\.0\.1:\d+${MISSING_PAGE}” was blocked`, - String.raw`^console:error:Failed to load resource: the server responded with a status of 404 \(Not Found\)$`, - String.raw`^console:error:JSHandle@object$`, - String.raw`^console:error:TypeError: Importing a module script failed\.$`, - ].join("|"), - "u", - ), + allowedBrowserFailure: async ({ browserName }, provide) => { + const patterns = [...MISSING_PAGE_FAILURES]; + if (browserName === "webkit") { + if (!builds) throw new Error("Fixture builds were not prepared."); + const files = [ + ...(await preloadedWith(builds.dist.a, PLATFORM_PAGE)), + ...(await preloadedWith(builds.dist.b, UI_PAGE)), + ].map((file) => file.replaceAll(".", String.raw`\.`)); + patterns.push( + String.raw`^console:warning:The resource http://127\.0\.0\.1:\d+/(?:${files.join("|")}) was preloaded using link preload but not used within a few seconds from the window's load event\. Please make sure it wasn't preloaded for nothing\.$`, + ); + } + await provide(new RegExp(patterns.join("|"), "u")); + }, }); test("an old tab reloads once into the new build, then stops reloading", async ({