Menu

Node.js Vercel Functions now support per-path request cancellation  - Vercel
📰

Node.js Vercel Functions now support per-path request cancellation - Vercel

Vercel News·Craig Andrews·5 months ago
#QlrM38rV
#vercel#signal#request#const#abort
Reading 0:00
15s threshold

Vercel Functions using Node.js can now detect when a request is cancelled and stop execution before completion. This is configurable on a per-path basis, and includes actions like navigating away, closing a tab, or hitting stop on an AI chat to terminate compute processing early.

This reduces unnecessary compute, token generation, and sending data the user would never see.

To enable cancellation, add "supportsCancellation": true to your vercel.json configuration. You can apply it to specific paths or all functions:

{

"functions" : {

"api/*" : {

"supportsCancellation" : true

}

}

}

Once enabled, you can listen for cancellation using Request.signal.aborted or the abort event:

export const GET = async ( req : Request ) => {

const abortController = new AbortController ( ) ;

req . signal . addEventListener ( "abort" , ( ) => {

console . log ( "request aborted" ) ;

abortController .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.