next.js
854fdb03 - instant(): Block out-of-band client fetches (#93099)

Commit
134 days ago
instant(): Block out-of-band client fetches (#93099) The Instant Navigation Testing API simulates what a user would see on an arbitrarily slow connection — like an infinitely slow network — when the app is at rest and the prefetch cache is completely warm. It works by blocking any dynamic RSC data fetches until the end of the testing scope (i.e. the callback passed to instant()). It's designed to test the behavior of data fetched by Next.js, via a Server Component. So currently, it does not affect the behavior out-of-band client fetches — e.g. fetch('/api/...') in useEffect or an external data fetching library. Those requests proceed without being blocked by the `instant()` scope. But this is misleading for testing purposes, because it implies that client-side data fetches are not affected by slow network conditions. To address this, this PR overrides the global `fetch` API and blocks out-of-band client fetches until the lock is released. The change also impacts the behavior of the Instant DevTools panel (since both tools use the same underlying mechanism). The change only affects environments where the Instant Navigation Testing API is enabled. It has no impact on live production behavior. It does not account for other sources of I/O, like images, scripts, fonts, etc. <!-- NEXT_JS_LLM_PR -->
Author
Parents
Loading