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
5b4b95e2
Unverified
Commit
5b4b95e2
authored
Oct 26, 2026
by
vercel-fleet-prod[bot]
Committed by
GitHub
Oct 26, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix route timeout for stalled CSS
Co-authored-by:
Tobias Koppers
<
1365881+sokra@users.noreply.github.com
>
parent
b5896b87
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
26 deletions
+37
-26
next-turbopack.ts
packages/next/src/client/next-turbopack.ts
+25
-7
route-loader.ts
packages/next/src/client/route-loader.ts
+12
-19
No files found.
packages/next/src/client/next-turbopack.ts
View file @
5b4b95e2
...
@@ -22,8 +22,10 @@ window.next = {
...
@@ -22,8 +22,10 @@ window.next = {
// for the page loader
// for the page loader
declare
let
__turbopack_load__
:
any
declare
let
__turbopack_load__
:
any
// Map of page route -> promise that settles once the page's chunks finish
type
PageChunkData
=
string
|
{
path
:
string
}
// loading. The route loader consumes these promises in production builds.
// Map of page route -> promise that settles once the page's executable chunks
// finish loading. The route loader consumes these promises in production.
// Creating the map eagerly also lets the route loader detect Turbopack.
// Creating the map eagerly also lets the route loader detect Turbopack.
const
turbopackPageChunkPromises
=
new
Map
<
string
,
Promise
<
unknown
>>
()
const
turbopackPageChunkPromises
=
new
Map
<
string
,
Promise
<
unknown
>>
()
;(
self
as
any
).
__TURBOPACK_PAGE_CHUNK_PROMISES__
=
turbopackPageChunkPromises
;(
self
as
any
).
__TURBOPACK_PAGE_CHUNK_PROMISES__
=
turbopackPageChunkPromises
...
@@ -33,15 +35,31 @@ initialize({})
...
@@ -33,15 +35,31 @@ initialize({})
// for the page loader
// for the page loader
;(
self
as
any
).
__turbopack_load_page_chunks__
=
(
;(
self
as
any
).
__turbopack_load_page_chunks__
=
(
page
:
string
,
page
:
string
,
chunksData
:
any
chunksData
:
PageChunkData
[]
)
=>
{
)
=>
{
const
chunkPromises
=
chunksData
.
map
((
c
:
unknown
)
=>
const
chunkLoads
=
chunksData
.
map
((
chunkData
)
=>
({
__turbopack_load__
(
c
)
chunkData
,
)
promise
:
__turbopack_load__
(
chunkData
),
}))
const
chunksPromise
=
Promise
.
all
(
chunkPromises
).
catch
((
err
)
=>
// Preserve loading and error reporting for every chunk. CSS remains
// subject to the route timeout, and the shared runtime is already active,
// so only executable page chunks postpone that timeout.
Promise
.
all
(
chunkLoads
.
map
(({
promise
})
=>
promise
)).
catch
((
err
)
=>
console
.
error
(
'failed to load chunks for page '
+
page
,
err
)
console
.
error
(
'failed to load chunks for page '
+
page
,
err
)
)
)
const
chunksPromise
=
Promise
.
all
(
chunkLoads
.
filter
(({
chunkData
})
=>
{
const
chunkPath
=
typeof
chunkData
===
'string'
?
chunkData
:
chunkData
.
path
return
(
!
chunkPath
.
endsWith
(
'.css'
)
&&
!
/
(?:
^|
\/)
turbopack-
[^/]
+
\.
js$/
.
test
(
chunkPath
)
)
})
.
map
(({
promise
})
=>
promise
)
).
catch
(()
=>
{})
turbopackPageChunkPromises
.
set
(
page
,
chunksPromise
)
turbopackPageChunkPromises
.
set
(
page
,
chunksPromise
)
}
}
...
...
packages/next/src/client/route-loader.ts
View file @
5b4b95e2
...
@@ -254,7 +254,7 @@ export function createRouteLoader(assetPrefix: string): RouteLoader {
...
@@ -254,7 +254,7 @@ export function createRouteLoader(assetPrefix: string): RouteLoader {
// Bootstrap a client-loaded route (navigation/prefetch) so its entry registers via
// Bootstrap a client-loaded route (navigation/prefetch) so its entry registers via
// `window.__NEXT_P`. The initial page is bootstrapped in the document.
// `window.__NEXT_P`. The initial page is bootstrapped in the document.
function
bootstrapRoute
(
route
:
string
):
Promise
<
unknown
>
|
undefine
d
{
function
bootstrapRoute
(
route
:
string
):
voi
d
{
// Gated for DCE
// Gated for DCE
if
(
!
process
.
env
.
__NEXT_TURBOPACK_SHARED_RUNTIME
)
return
if
(
!
process
.
env
.
__NEXT_TURBOPACK_SHARED_RUNTIME
)
return
if
(
process
.
env
.
NODE_ENV
===
'development'
)
return
if
(
process
.
env
.
NODE_ENV
===
'development'
)
return
...
@@ -264,7 +264,7 @@ export function createRouteLoader(assetPrefix: string): RouteLoader {
...
@@ -264,7 +264,7 @@ export function createRouteLoader(assetPrefix: string): RouteLoader {
if
(
params
==
null
)
return
if
(
params
==
null
)
return
// `global` is always defined alongside the params map (see manifest-loader).
// `global` is always defined alongside the params map (see manifest-loader).
bootstrappedRoutes
.
add
(
route
)
bootstrappedRoutes
.
add
(
route
)
return
(
self
as
any
)[
global
!
].
push
(
params
)
;
(
self
as
any
)[
global
!
].
push
(
params
)
}
}
function
maybeExecuteScript
(
function
maybeExecuteScript
(
...
@@ -359,10 +359,10 @@ export function createRouteLoader(assetPrefix: string): RouteLoader {
...
@@ -359,10 +359,10 @@ export function createRouteLoader(assetPrefix: string): RouteLoader {
})
})
}
}
// In Turbopack production, loading a route
starts asynchronous chunk
// In Turbopack production, loading a route
can start asynchronous
//
work after its loader script finishes. Delay the entrypoint
timeout
//
JavaScript work after its loader script finishes. Delay the
timeout
// until that known
work settles. The eagerly-created map identifie
s
// until that known
JavaScript work settles. Do not include CSS in thi
s
//
Turbopack without changing webpack production behavior
.
//
delay: stalled styles must still trigger the route timeout
.
const
turbopackChunkPromises
=
self
.
__TURBOPACK_PAGE_CHUNK_PROMISES__
const
turbopackChunkPromises
=
self
.
__TURBOPACK_PAGE_CHUNK_PROMISES__
let
chunksLoaded
:
Promise
<
void
>
|
undefined
let
chunksLoaded
:
Promise
<
void
>
|
undefined
let
chunksLoadedResolve
:
(()
=>
void
)
|
undefined
let
chunksLoadedResolve
:
(()
=>
void
)
|
undefined
...
@@ -379,23 +379,16 @@ export function createRouteLoader(assetPrefix: string): RouteLoader {
...
@@ -379,23 +379,16 @@ export function createRouteLoader(assetPrefix: string): RouteLoader {
?
Promise
.
resolve
([])
?
Promise
.
resolve
([])
:
Promise
.
all
(
scripts
.
map
(
maybeExecuteScript
)).
then
(
:
Promise
.
all
(
scripts
.
map
(
maybeExecuteScript
)).
then
(
async
(
result
)
=>
{
async
(
result
)
=>
{
// Shared-runtime builds expose the chunk-loading promise
// The page-loader stub synchronously records its
// as the return value of the bootstrap registration.
// non-CSS chunk promise before its script load event.
const
bootstrapPromise
=
bootstrapRoute
(
route
)
// Shared-runtime routes also need bootstrap registration
// to instantiate the entrypoint once those chunks load.
// Stable and legacy builds load a page through a stub
bootstrapRoute
(
route
)
// that records its chunk-loading promise in this map.
const
chunkPromise
=
turbopackChunkPromises
?.
get
(
route
)
const
chunkPromise
=
turbopackChunkPromises
?.
get
(
route
)
if
(
chunkPromise
)
{
if
(
chunkPromise
)
{
turbopackChunkPromises
?.
delete
(
route
)
turbopackChunkPromises
?.
delete
(
route
)
await
chunkPromise
}
}
// The shared-runtime stub also populates the legacy
// map, but that promise only settles once the route has
// been bootstrapped, so awaiting it first would
// deadlock. Fall back to it when this route has no
// bootstrap params.
await
(
bootstrapPromise
??
chunkPromise
)
return
result
return
result
}
}
)
)
...
...
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