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
cdd12b21
Commit
cdd12b21
authored
Oct 20, 2025
by
Janka Uryga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
squash
parent
cdf79f25
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
5 deletions
+34
-5
staged-validation.tsx
packages/next/src/server/app-render/staged-validation.tsx
+34
-5
No files found.
packages/next/src/server/app-render/staged-validation.tsx
View file @
cdd12b21
...
@@ -32,14 +32,15 @@ export async function anySegmentHasRuntimePrefetchEnabled(
...
@@ -32,14 +32,15 @@ export async function anySegmentHasRuntimePrefetchEnabled(
return
false
return
false
}
}
export
type
StageChunks
=
Record
<
RenderStage
,
Uint8Array
[]
>
export
type
StageChunks
=
{
chunks
:
ChunksByStage
;
finishedIn
:
RenderStage
}
export
type
ChunksByStage
=
Record
<
RenderStage
,
Uint8Array
[]
>
export
function
collectStageChunksFromStagedRender
(
export
function
collectStageChunksFromStagedRender
(
stream
:
ReadableStream
<
Uint8Array
>
,
stream
:
ReadableStream
<
Uint8Array
>
,
getCurrentStage
:
()
=>
RenderStage
getCurrentStage
:
()
=>
RenderStage
):
Promise
<
StageChunks
>
{
):
Promise
<
StageChunks
>
{
let
lastChunkStage
:
RenderStage
|
null
=
null
let
lastChunkStage
:
RenderStage
|
null
=
null
const
chunks
:
StageChunks
=
{
const
chunks
:
ChunksByStage
=
{
[
RenderStage
.
Static
]:
[],
[
RenderStage
.
Static
]:
[],
[
RenderStage
.
Runtime
]:
[],
[
RenderStage
.
Runtime
]:
[],
[
RenderStage
.
Dynamic
]:
[],
[
RenderStage
.
Dynamic
]:
[],
...
@@ -55,9 +56,8 @@ export function collectStageChunksFromStagedRender(
...
@@ -55,9 +56,8 @@ export function collectStageChunksFromStagedRender(
}
catch
(
err
)
{
}
catch
(
err
)
{
return
reject
(
err
)
return
reject
(
err
)
}
}
const
currentStage
=
getCurrentStage
()
if
(
!
item
.
done
)
{
if
(
!
item
.
done
)
{
const
currentStage
=
getCurrentStage
()
// If we changed to a new stage, we have to copy over the chunks emitted in the previous stage --
// If we changed to a new stage, we have to copy over the chunks emitted in the previous stage --
// stage N+1 is a superset of stage N.
// stage N+1 is a superset of stage N.
if
(
lastChunkStage
!==
null
&&
lastChunkStage
!==
currentStage
)
{
if
(
lastChunkStage
!==
null
&&
lastChunkStage
!==
currentStage
)
{
...
@@ -68,8 +68,37 @@ export function collectStageChunksFromStagedRender(
...
@@ -68,8 +68,37 @@ export function collectStageChunksFromStagedRender(
lastChunkStage
=
currentStage
lastChunkStage
=
currentStage
}
else
{
}
else
{
// TODO: we should consider an API that allows yielding a stage's chunks as soon as it completes
// TODO: we should consider an API that allows yielding a stage's chunks as soon as it completes
return
resolve
(
chunks
)
return
resolve
(
{
chunks
,
finishedIn
:
currentStage
}
)
}
}
}
}
})
})
}
}
export
function
recreateServerStreamInStage
(
stageChunks
:
StageChunks
,
stage
:
RenderStage
)
{
// If we're recreating a stream for a stage before the stream ended,
// then it won't be a complete RSC stream.
// (i.e. it'll contain references to rows that never appear).
// In that case, the stream should stay unclosed to avoid "Connection Closed" from Fizz.
// (see `createUnclosingPrefetchStream` for more explanation)
const
shouldClose
=
stage
<
stageChunks
.
finishedIn
?
false
:
true
return
streamFromChunks
(
stageChunks
.
chunks
[
stage
],
shouldClose
)
}
function
streamFromChunks
(
chunks
:
Uint8Array
[],
shouldClose
:
boolean
=
true
):
ReadableStream
<
Uint8Array
>
{
return
new
ReadableStream
({
start
(
controller
)
{
for
(
const
chunk
of
chunks
)
{
controller
.
enqueue
(
chunk
)
}
if
(
shouldClose
)
{
controller
.
close
()
}
},
})
}
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