Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
a57784cb
Commit
a57784cb
authored
Jan 30, 2026
by
Ethan Niser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use waitUntil to keep WebSocket connections alive in serverless
parent
d3a42993
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
1 deletion
+9
-1
router-server.ts
packages/next/src/server/lib/router-server.ts
+9
-1
No files found.
packages/next/src/server/lib/router-server.ts
View file @
a57784cb
...
@@ -61,6 +61,7 @@ import {
...
@@ -61,6 +61,7 @@ import {
}
from
'./chrome-devtools-workspace'
}
from
'./chrome-devtools-workspace'
import
{
getNextConfigRuntime
,
type
NextConfigComplete
}
from
'../config-shared'
import
{
getNextConfigRuntime
,
type
NextConfigComplete
}
from
'../config-shared'
import
{
bridgeWebSocket
}
from
'../web/websocket-bridge'
import
{
bridgeWebSocket
}
from
'../web/websocket-bridge'
import
{
getBuiltinRequestContext
}
from
'../after/builtin-request-context'
const
debug
=
setupDebug
(
'next:router-server:main'
)
const
debug
=
setupDebug
(
'next:router-server:main'
)
const
isNextFont
=
(
pathname
:
string
|
null
)
=>
const
isNextFont
=
(
pathname
:
string
|
null
)
=>
...
@@ -897,7 +898,14 @@ export async function initialize(opts: {
...
@@ -897,7 +898,14 @@ export async function initialize(opts: {
}
}
// Bridge the WebSocket
// Bridge the WebSocket
await
bridgeWebSocket
(
req
,
socket
,
head
,
wsInternalData
)
// Use waitUntil if available (for serverless environments like Vercel)
// to keep the function alive while the WebSocket connection is open
const
bridgePromise
=
bridgeWebSocket
(
req
,
socket
,
head
,
wsInternalData
)
const
waitUntil
=
getBuiltinRequestContext
()?.
waitUntil
if
(
waitUntil
)
{
waitUntil
(
bridgePromise
)
}
await
bridgePromise
return
{
handled
:
true
}
return
{
handled
:
true
}
}
catch
(
err
)
{
}
catch
(
err
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment