Files
Andrew ClarkandGitHub a060fbf9f7 Deflake per-page dynamic stale time test (#91492)
## Summary

- Fixes flaky test "per-page value overrides global staleTimes.dynamic
regardless of direction" introduced by #91437
- The test was flaky because `browser.back()` restored accordion state
from BFCache, causing previously-opened `LinkAccordion` links to be
immediately visible. This triggered uncontrolled re-prefetches outside
the `act` scope. When the `IntersectionObserver` fired inside a
subsequent `act` scope (after clock advancement), stale data would
trigger a prefetch that violated the `no-requests` assertion.
- Fix: instead of navigating back to a previously visited page, navigate
forward to fresh "hub" pages with their own `LinkAccordion` components.
Since these are never-visited pages, accordions start closed and no
uncontrolled prefetches are triggered.
- General principle: when using the router `act` test utility, always
use `LinkAccordion` to control when prefetches happen. Prefetches should
only be triggered inside an `act` scope by toggling an accordion, never
by navigating back to a page where links are already visible.

## Test plan

- [x] Ran the full test file 4 times locally — all 5 tests pass
consistently
2026-03-17 09:14:19 -04:00

31 lines
704 B
TypeScript

import { Suspense } from 'react'
import { connection } from 'next/server'
import { LinkAccordion } from '../../../components/link-accordion'
export const unstable_dynamicStaleTime = 60
async function Content() {
await connection()
return (
<div id="dynamic-stale-60-content">Dynamic content (stale time 60s)</div>
)
}
export default function Page() {
return (
<>
<Suspense fallback="Loading...">
<Content />
</Suspense>
<ul>
<li>
<LinkAccordion href="/per-page-config/hub-a">Hub A</LinkAccordion>
</li>
<li>
<LinkAccordion href="/per-page-config/hub-c">Hub C</LinkAccordion>
</li>
</ul>
</>
)
}