Skip to content

Deflake per-page dynamic stale time test#91492

Open
acdlite wants to merge 1 commit intocanaryfrom
acdlite/deflake-per-page-stale-time-test
Open

Deflake per-page dynamic stale time test#91492
acdlite wants to merge 1 commit intocanaryfrom
acdlite/deflake-per-page-stale-time-test

Conversation

@acdlite
Copy link
Contributor

@acdlite acdlite commented Mar 17, 2026

Summary

  • Fixes flaky test "per-page value overrides global staleTimes.dynamic regardless of direction" introduced by Add unstable_dynamicStaleTime route segment config #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

  • Ran the full test file 4 times locally — all 5 tests pass consistently

@nextjs-bot nextjs-bot added created-by: Next.js team PRs by the Next.js team. tests labels Mar 17, 2026
The "per-page value overrides global staleTimes.dynamic regardless of
direction" test was flaky because it used browser.back() to return to
/per-page-config where accordion state was restored from BFCache. This
caused previously-opened LinkAccordion links to be immediately visible,
triggering uncontrolled re-prefetches outside the act scope. When the
IntersectionObserver fired inside the 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 that have their own LinkAccordion
components. Since these are never-visited pages, the accordions start
closed and no uncontrolled prefetches are triggered. Each hub page is
dynamic (uses connection()) so act can properly manage the RSC requests
during navigation.

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.
@acdlite acdlite force-pushed the acdlite/deflake-per-page-stale-time-test branch from 5c5f76f to 18e57cd Compare March 17, 2026 05:39
@nextjs-bot
Copy link
Collaborator

nextjs-bot commented Mar 17, 2026

Tests Passed

@acdlite acdlite marked this pull request as ready for review March 17, 2026 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

created-by: Next.js team PRs by the Next.js team. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants