next.js
90f8f114 - test: wait for use-cache recovery reload (#102224)

Commit
3 hours ago
test: wait for use-cache recovery reload (#102224) ### What? Stabilizes `use-cache-without-experimental-flag` › *should recover from the build error if useCache flag is set* in dev. Test-only; no framework changes. ### Why? After the test enables `experimental.useCache`, the harness waits for the restarted dev server to be ready, but the browser still shows the old build-error document. The dev client recovers with a full page reload, and that reload only commits once the restarted server has compiled `/`. Until then, `elementByCss('p')` matches the old document's empty route announcer (`p#__next-route-announcer__`), so the early reads fail. A read that is in flight when the reload starts is blocked until the reload commits. By then the 3 s `retry()` window has been used up. Depending on which call was in flight, the final error is either: - `elementHandle.innerText: Execution context was destroyed, most likely because of a navigation`, or - `page.waitForSelector: Timeout 5000ms exceeded`. Both show up on canary and heal on the runner's in-job retry, so jobs stay green. In the latest attempts of the 100 newest canary `build-and-test` push runs, there were 6 `innerText` context-destroyed failures (webpack and Turbopack dev) and one selector timeout. Example: [run 44786344811, job 136465407045](https://github.com/vercel/next.js/actions/runs/44786344811/job/136465407045). ### How? Before patching `next.config.js`, mark the build-error document. In the patch callback, wait with `waitForCondition` until the marker is gone, i.e. until the reload has replaced the document. The existing `hello world` text check and no-redbox check are unchanged. No sleeps, timeout arguments, extra retries or skips. ### Verification Ran only the recovery case, with jest directly (no runner retries), on webpack dev. Env: `NEXT_TEST_REACT_VERSION=18.3.1`, `__NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true`, `HEADLESS=true`. Each batch ran on a deliberately busy host: dev server pinned to one CPU with one busy loop, Chromium pinned to another CPU with three busy loops. These counts reproduce the race; they are not CI failure-rate estimates. | Variant | Passed | Exact `innerText` context-destroyed failures | Other failures | |---|---:|---:|---| | Unmodified | 18/30 | 2/30 | 10 selector timeouts | | This change | 20/20 | 0/20 | — | | This change with only `waitForCondition` removed | 18/30 | 1/30 | 11 selector timeouts | Unloaded runs with the same env also passed: webpack dev 2/2 cases, Turbopack dev 2/2, webpack start 1/1. - Not run: rspack dev locally (bindings not installed). <!-- NEXT_JS_LLM --> <!-- fleet a766742f-56ef-446c-99b7-d06b02bcc8fa --> Co-authored-by: vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com> Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
Author
Parents
Loading