Disable prefetching in draft mode
With Cache Components enabled, draft-mode prefetches bypass prerendered output and can receive full dynamic RSC responses. The loading-boundary fallback can cache completed content using static-stage param dependencies, allowing sibling URLs to reuse the wrong content. We considered preserving prefetching by fixing request scoping and skipping staged rendering for draft responses. That still performs speculative server work and can retain preview content after a CMS edit. Disabling draft prefetches avoids creating those speculative snapshots, without on-demand segment prerenders or a blanket restriction on valid vary-param reuse. This change pauses the prefetch scheduler while draft mode is enabled. The initial RSC payload reports the draft state, and a Server Action that writes the draft cookie reports the new state in a response header, so the router applies it before Flight decoding and before cache invalidation reschedules visible links. Paused tasks stay queued and resume through the existing revalidation cooldown once draft mode is disabled, including when the action response body fails to decode. Normal navigation and cache-consumption policies remain unchanged, and the Instant Navigation Testing API can still run the foreground tasks needed to complete a navigation. The router learns the state only from the initial document and from Server Actions. A Route Handler that toggles the cookie and is called with a client-side `fetch()` followed by `router.refresh()` leaves the prefetching state unchanged until the next page load; the docs now say to redirect from such a handler. Forwarded Server Actions now also pass the worker's `Set-Cookie` headers through to the browser. They were previously dropped together with the other `actionsForbiddenHeaders`, so a `cookies().set()` inside a forwarded action never reached the client. Draft mode depends on this, but it applies to every cookie a forwarded action writes.
Showing
This diff is collapsed.
Please
register
or
sign in
to comment