next.js
c58836ae - Fix cache revalidation queued during streaming (#100448)

Commit
6 days ago
Fix cache revalidation queued during streaming (#100448) Next.js previously flushed revalidations after preparing the HTML stream or running a Route Handler, before the response body finished streaming. That flush dispatched queued tags and collected existing background cache promises. Work added during streaming was omitted, so later cache regeneration lacked `waitUntil` coverage and later tag invalidations were never dispatched. This extends the response-close approach proposed in #99772 beyond dynamic HTML to Flight responses, Route Handlers, and streamed Server Actions. `AfterContext` registers a `waitUntil` promise before the handler returns and flushes newly queued work at close. Its snapshot excludes earlier flushes and runs before `after()` callbacks start, so their invalidations wait for callback completion. The change also handles already-closed Node responses and Edge error paths that must release close waiters. Server Action barriers retain their existing ordering. Fixes #99339 Fixes #99566 Closes #99772
Author
Parents
Loading