-
Notifications
You must be signed in to change notification settings - Fork 26.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NEXT-1318] Unable to use context.waitUntil in Route Handler? #50522
Comments
Hey @s1973 have you managed to figure this out yet? |
@balazsorban44 is this a Next.js bug? And if so, any estimate as to when context.waitUntil would become available? |
Hi, it's more like a missing feature. when Route Handlers have been introduced this was not added to the initial implementation requirements. But after some internal discussions, we think we should add it so there's feature parity with API Routes (edge). It's now tracked internally. |
Got it. Thank you! Will keep an eye out since it's blocking us from migrating some pretty important routes to the app directory. |
Hey @balazsorban44 , is this being worked on yet by any chance? If so can I have a rough ETA? Thank you & I really appreciate it! |
+1 on this Kind of strange that this was released without this feature. The types are literally wrong in saying there is this property that doesn't exist (waitUntil). Had to move some routes to page router as a result of it. |
This comment has been minimized.
This comment has been minimized.
Were you able to access the context object using page router? Mine is an empty object. |
I was able to get around this issue by moving my long-running functions to export async function middleware(req, context) {
if(/*match your path*/)
{
context.waitUntil(callFunctionsThatReturnsPromise);
}
} |
Great workaround @anuraagvaidya , but pretty inconvenient for large apps with lots of moving pieces & routes. Really hoping to see native context support at a route level |
This comment has been minimized.
This comment has been minimized.
The Next.js team has created an undocumented (and highly experimental) API for this:
"use server";
import { internal_runWithWaitUntil as waitUntil } from "next/dist/server/web/internal-edge-wait-until";
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
export async function action() {
console.log("Request received");
waitUntil(async () => {
await sleep(10000);
console.log("Waited for 10 seconds");
});
return "Returned immediately";
} |
@sam3d I'm wondering if there's an update on when this is being planned to be released? |
Yeah feels weird that there were 2(!!) major versions with app router released without this kinda important feature. |
using internal_runWithWaitUntil But any eta when the api will be stabilised in a release? |
It's brewing! #65038 |
until recently, there was no way of using waitUntil in vercel edge. vercel/next.js#50522 But now it is possible. Updating the nextjs and vercel-edge examples utilizing the waitUntil.
What is the improvement or update you wish to see?
When using pages router, we can use context on api routers:
while using app router, we got this from doc:
so I am wondering how to use NextFetchEvent with route handler?
Is there any context that might help us understand?
I am trying to keep the function running after a response has been sent, as the vercel doc navigated, we can use
waitUntil()
, but it seems not approachable in App Router and Route Handler, can I get any thoughts? thanksDoes the docs page already exist? Please link to it.
https://nextjs.org/docs/app/api-reference/file-conventions/route#context-optional
NEXT-1318
The text was updated successfully, but these errors were encountered: