Add Instant Navigation Testing API (#89465)
## Summary
Adds a dev-mode primitive for writing e2e tests that assert on the
prefetched/cached portion of a navigation. The API blocks dynamic data
from streaming in until assertions complete, allowing deterministic
testing of loading states without race conditions.
This gives developers a way to verify that specific UI elements render
instantly from cache, rather than relying on network timing. It also
reinforces the mental model that navigation performance should be
thought of primarily in terms of cached vs. dynamic.
This PR implements the primitive that Next.js exposes on the window
object. In practice, it's meant to be used via a testing framework
integration, like a Playwright helper:
```typescript
await instant(page, async () => {
await page.click('a[href="/products/123"]');
await expect(page.locator('[data-testid="skeleton"]')).toBeVisible();
});
```
The implementation forces a prefetch before navigation when inside an
`instant` scope (since prefetching is normally disabled in dev), then
holds dynamic data until the scope ends. All code is wrapped in dev
checks and gets dead code eliminated in production.
Current scope is client-side navigations only. SSR/MPA support is
planned as a follow-up.
## Test plan
- `test/e2e/app-dir/instant-navigation-testing-api`
Showing
Please
register
or
sign in
to comment