Licence
Apache-2.0
Version
0.5.0
Deps
1
Size
13 kB
Vulns
0
Weekly
0
@use-crux/next
Next.js host integration for Crux request-scoped defer().
Install
pnpm add @use-crux/next @use-crux/core
Requires Next.js 15.1+ (after from next/server).
Usage
import { defer } from '@use-crux/core'
import { withCrux } from '@use-crux/next'
export const POST = withCrux(async () => {
defer(() => {
// Runs after the response finishes (response-finished class).
})
return Response.json({ ok: true })
})
Application code always imports defer from @use-crux/core. This package only
installs the Next lifetime boundary. withCrux also schedules a bounded final
observability drain through the same after() port without holding the response
open. Pass onDrain to inspect incomplete delivery. withNextDefer remains
available when only the low-level defer lifetime is wanted.
Named durable work still needs a configured Crux Runtime:
export const POST = withCrux(
async () => {
await defer(sendEmail, { messageId: '1' })
return Response.json({ ok: true })
},
{ durableFinalization: true },
)