-
Notifications
You must be signed in to change notification settings - Fork 81
Closed
Labels
Description
Describe the bug
I'm currently using getCloudflareContext() to call context.waitUntil() manually for background tasks. I would like to migrate to the standardized after() API from next/server which should be supported according to docs.
When using the Cloudflare OpenNext adapter (next dev server works fine), asynchronous logic added with next/after does not consistently execute as expected. Sometimes async operations complete successfully, other times they are cut off prematurely or never awaited properly.
Steps to reproduce
import { after } from "next/server";
export const doSomethingAsync = async (input: any) => {
// Simulate main logic
const result = await someMainOperation(input);
// Async follow-up task
after(async () => {
// This sometimes runs, sometimes doesn't
await someAsyncSideEffect(result);
});
return result;
};
Expected behavior
Should reliably execute the async function after the response is returned.
@opennextjs/cloudflare version
1.9.0
Wrangler version
4.30.0
next info output
Relevant Packages:
next: 15.4.6 // There is a newer version (15.5.4) available, upgrade recommended!
eslint-config-next: 15.4.6
react: 19.1.0
react-dom: 19.1.0
typescript: 5.9.2Additional context
No response