next.js
112872f3 - test: avoid idle-callback starvation in css-client-nav (#102132)

Commit
1 day ago
test: avoid idle-callback starvation in css-client-nav (#102132) ### What? Stabilizes the `css-client-nav` e2e test for timing out a stalled CSS request and falling back to hard navigation. ### Why? The Pages Router arms its route-loading timeout from `requestIdleCallback`. In this test, after the Playwright click, that idle callback was sometimes starved until the stalled CSS resolved. The client-side navigation then completed instead of hard-navigating, causing: ```text expect(await browser.eval('window.beforeNav')).toBeFalsy() Received: "hello" ``` Temporary diagnostic timing logs on failures showed the idle callback firing after about 5,020 ms, after the five-second CSS delay. Passing runs fired it after about 10–20 ms. The starvation is not specific to automated (CDP) input. A follow-up check with headed Chromium, real X11 input and no DevTools attached saw it after clicks, hover and Tab+Enter. It also happened with no input at all, in 6 of 10 fresh browser instances in one batch. The state appears to be Chromium-side and set during page load. Mechanism details are in [this review comment](https://github.com/vercel/next.js/pull/102132#discussion_r4642721452). With the DOM click, this test did not fail in the A/B runs below. ### How? The test now invokes the existing `<Link>` click handler by calling `document.querySelector('#link-blue').click()` instead of using Playwright mouse input. **Coverage trade-off:** this test no longer exercises the real Playwright mouse-input path. It still covers the stalled CSS request, router timeout and hard-navigation fallback through the same `<Link>` handler. The other navigation tests in this file still use Playwright's mouse click. No runtime or framework code changes. Real input can also starve `requestIdleCallback`. In the same follow-up check, though, the Pages Router's 3.8 s fallback fired on schedule in 17/17 runs, including an async-then-`router.push` flow under 8-core CPU load. No user-visible impact was reproduced, so no product change is proposed. This PR does not change the timeout policy. This is unrelated to the separate `next-dynamic-css` CSS cascade flake in #102027. ### Verification Run on an 8-vCPU Linux sandbox. The burner setup used 8 shell busy loops, plus a 16-loop stress run. Exact single-attempt repro loop (run from the repo root; build first if needed): ```bash pids=() for i in $(seq 1 8); do (while :; do :; done) & pids+=("$!"); done trap 'kill "${pids[@]}" 2>/dev/null' EXIT fail=0 for i in $(seq 1 15); do NEXT_TEST_CI=true pnpm test-start-webpack \ test/e2e/css-client-nav/css-client-nav.test.ts -t "stalled" \ > "/tmp/css-client-nav-$i.log" 2>&1 || fail=$((fail + 1)) done echo "$fail/15 failed" ``` | Configuration | Result | |---|---| | Original test, 8 burners, direct Jest single attempts | **4/15 failed** | | This PR, same 8-burner loop with `30` iterations | **0/30 failed** | | This PR, same loop with 16 burners and `12` iterations | **0/12 failed** | | This PR, full file through `run-tests.js` with `--retries 0`, 8 burners | **10/10 passed** | | Webpack full file, no burners | **5/5 passed** | | Turbopack full file, no burners | **5/5 passed** | Mutation check: I temporarily changed the compiled route-loader timeout from `3800` to `60000`. The updated test failed again with `Received: "hello"`, confirming it still catches a broken timeout-to-hard-navigation fallback. The compiled files were restored. Repo harness run used for the full-file no-retry check: ```bash pids=() for i in $(seq 1 8); do (while :; do :; done) & pids+=("$!"); done trap 'kill "${pids[@]}" 2>/dev/null' EXIT NEXT_TEST_MODE=start IS_WEBPACK_TEST=1 HEADLESS=true NEXT_TEST_CI=true \ node run-tests.js --type e2e --retries 0 --runs 10 --concurrency 1 \ test/e2e/css-client-nav/css-client-nav.test.ts ``` Also passed: Prettier, ESLint and `git diff --check` for the changed file. <!-- NEXT_JS_LLM --> <!-- fleet a76e69ba-9e92-4493-b333-52215c3ae125 --> 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