rsnext/packages/next-swc/crates
Janka Uryga 79bebe7bd3
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`
2024-05-20 08:49:53 +00:00
..
napi Reapply "Implement Turbopack trace server bindings" (#65419) (#65527) 2024-05-13 18:59:59 +02:00
next-api Turbopack: Remove EcmascriptChunkingContext (#65716) 2024-05-15 15:51:08 +00:00
next-build chore: remove unused rust dependencies (#62176) 2024-04-16 17:48:06 +02:00
next-core experimental: unstable_after (#65038) 2024-05-20 08:49:53 +00:00
next-custom-transforms experimental: unstable_after (#65038) 2024-05-20 08:49:53 +00:00
wasm Update turbopack & swc_core (#65450) 2024-05-17 20:15:51 +02:00