docs: use visible route locators with Cache Components (#101346)
## Summary
With Cache Components enabled, client-side navigation preserves previous
pages as hidden DOM. Broad test locators can count hidden elements or
fail Playwright strict mode after navigation.
- **Playwright guide:** use role locators in the navigation example and
link to the existing preserved-UI testing advice, extracted from
#100208.
- **Instant navigation guide:** use role locators for headings and
visibility filters for links and stock assertions, including zero-count
checks. Check the product fallback on initial loads because this example
has no generated params; check the heading after the scope releases.
Keep Partial Prefetching enabled in the production test config, matching
the guide’s quick start.
- **Cypress guide:** filter the navigation example to visible headings
and add an App Router caveat with the tool-specific filter and the
existing testing advice.
- **Starter examples:** keep the App Router tests in
`examples/with-playwright/e2e/app.spec.ts` and
`examples/with-cypress/cypress/e2e/app.cy.ts` aligned with the guides.
The preserving-UI-state guide already covers hidden-element matches and
filtering. Jest and Vitest examples mount isolated components and need
no route-preservation caveat.
Finding: https://next-maintainer-agent.vercel.tools/agent-feedback/5226
Related: #86577
## Verification
Ran the test code extracted from all five changed files, before and
after, against a standalone Turbopack production build with Cache
Components and Partial Prefetching enabled. Ports and starter route
prefixes were adapted; the store database calls were represented by
cached product data and request-time inventory. No evaluation files are
added to this PR.
Versions: Next.js 16.5.0-canary.43, React 19.3.1, `@next/playwright`
16.4.5, Playwright 1.65.0, Cypress 16.2.1 (headless Electron).
| Example | Before | After |
| --- | --- | --- |
| Playwright guide navigation | Strict-mode failure in Chromium,
Firefox, WebKit | Passes in all three |
| Playwright starter navigation | Strict-mode failure in all three |
Passes in all three |
| `instant()` client navigation | Strict-mode failure in all three |
Chromium/Firefox pass; WebKit passes locked-scope assertions but fails
after release |
| `instant()` initial page load | Product heading absent from the static
shell in all three | Corrected fallback/heading sequence passes in
Chromium/Firefox; WebKit fails after release |
| Cypress guide and starter | Both pass despite matching hidden headings
| Both pass and select only the visible heading |
Correctness controls:
- In all three Playwright browsers, role locators reject an incorrect
visible heading even when the expected heading remains hidden in the
DOM.
- Cypress’s original `contains()` assertion accepts expected text from a
hidden source route after navigating to a wrong visible heading. The
filtered assertion fails as intended. Total heading count is two;
visible count is one.
- With Partial Prefetching disabled, the revised stock absence assertion
fails when inventory is fully prefetched. It does not silently accept
visible dynamic content.
**WebKit limitation:** the product content remains locked after
`instant()` returns, even though the test cookie is gone. Unfiltered
locators fail too. A separate diagnostic releases the content by setting
and deleting the cookie inside the page; the same issue reproduces using
the repository’s Playwright 1.61.0 runner. This is separate from
hidden-route locator matching, and the full revised `instant()` tests
are not claimed to pass in WebKit.
Prettier and the repository ESLint config pass. The documented
`instant()` code was compared with the executed test after TypeScript
transpilation.
<!-- NEXT_JS_LLM -->