test: poll use-cache revalidation via HTML (#102175)
### What?
Stabilize the two server-cache revalidation assertions in
`use-cache.test.ts` (also run by
`use-cache.partial-prefetching.test.ts`). Test-only; no framework
changes.
### Why?
The first request after invalidation can serve stale data while it is
recomputed in the background. The tests poll by reloading the browser,
and a slow webpack dev page load can consume the retry budget before a
later request reads the refreshed value. `retry()` stops when `waited +
500 > 3000`, so a first attempt taking more than 2.5 s is terminal.
CI examples: [stale unstable_cache and fetch
revalidation](https://github.com/vercel/next.js/actions/runs/44786344811/job/136465407033).
In those logs, the post-invalidation GETs complete in tens of
milliseconds and cache-handler writes follow, but no second follow-up
GET happens before the assertions fail.
### How?
Poll the rendered HTML with `next.render$` instead of reloading the
browser. Keep the initial browser visit and server-action click. Require
the expected element to exist before comparing its value, so an error
document cannot pass as refreshed data. Once the retry has settled the
cache, reload the browser and assert the refreshed value there too.
No sleeps, timeout increases, additional retries or skips.
### Verification
Full-suite webpack dev runs on an 8-vCPU host, without injected delays
or throttling:
```sh
IS_WEBPACK_TEST=1 NEXT_TEST_MODE=dev NEXT_TEST_REACT_VERSION=18.3.1 \
__NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true HEADLESS=true \
node run-tests.js --type development --retries 0 --runs 12 -c 4 \
test/e2e/app-dir/use-cache/use-cache.test.ts
```
| Variant | Stale unstable_cache failures | Fetch revalidation failures
|
|---|---:|---:|
| Unmodified canary | 12/12 | 11/12 |
| This change | 0/12 | 0/12 |
| Only the polling change reverted | 12/12 | 12/12 |
- These are 12 independent full suites, run four at a time on a
deliberately busy local host. The local failure rate is not a CI rate
estimate; it reproduces the same request-order and timing pattern seen
in CI.
- In every failing baseline case, there is one follow-up GET, then a
cache write, but no second GET. The only passing baseline fetch case has
a second follow-up GET.
- Both full-suite partial-prefetching and webpack start runs passed;
partial-prefetching passed 4/4 concurrent runs at zero retries.
- Final change, uncontended focused runs: 3/3 passed.
- After adding the post-retry browser check (rebased on current canary):
12 runs at concurrency 4, `--retries 0`, 0/12 failures.
- Browser reload sends `cache-control: max-age=0`; the HTTP read sends
no cache-control. Neither triggers the dev cache bypass, which checks
for `no-cache`.
- Prettier and ESLint passed. Not run: repository-wide TypeScript,
Turbopack and deployment suites (scoped to test-only webpack
revalidation reads).
<!-- NEXT_JS_LLM -->
<!-- fleet 95a49a4d-329c-4157-820e-e0baf95e052a -->
---------
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>