-
Notifications
You must be signed in to change notification settings - Fork 26.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
experimental: unstable_after (#65038)
Implements `unstable_after`, which lets the user schedule work to be executed after the response is finished. ### Implementation notes - `unstable_after()` is a dynamic function (bypassable only with `export dynamic = "force-static"`) - Usable in: server components (including `generateMetadata`), actions, route handlers, middleware - It is meant to run its callbacks even if a response didn't complete successfully (thrown error) or called `notFound()`/`redirect()` - Currently gated behind a `experimental.after` feature flag, because it touches many runtime bits (including a React monkeypatch...) - The state for `unstable_after()` in a given request lives in `requestAsyncStorage` (added via `RequestAsyncStorageWrapper`) - the implementation is based around two functions that we inject via `renderOpts`: - `waitUntil(promise)` - keep a function invocation alive until a promise settles. it is provided as a platform primitive in serverless contexts, and a noop in `next start` - for serverless (nodejs), Next.js will attempt to get `waitUntil` from `globalThis[Symbol.for('@next/request-context')].get().waitUntil`. This should be considered unstable for now. See `packages/next/src/server/after/wait-until-builtin.ts` for details. - `onClose(callback)` **[NEW]** - run something when a response is done. basically `res.on('close', callback)`, but also implemented for Web APIs - unfortunately, for Web, this requires some potentially expensive tricks - see `packages/next/src/server/web/web-on-close.ts`
- Loading branch information
1 parent
3843166
commit 79bebe7
Showing
67 changed files
with
2,153 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.