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
ea1c09a2
Unverified
Commit
ea1c09a2
authored
Jul 06, 2026
by
Hendrik Liebau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address review feedback
parent
d37b6cdf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
55 deletions
+44
-55
app-render.tsx
packages/next/src/server/app-render/app-render.tsx
+41
-53
stream-ops.node.ts
packages/next/src/server/app-render/stream-ops.node.ts
+3
-2
No files found.
packages/next/src/server/app-render/app-render.tsx
View file @
ea1c09a2
...
...
@@ -849,7 +849,7 @@ async function generateDynamicFlightRenderResult(
// response-close to abort the discarded render. This is the
// non-Cache-Components dev RSC path; unlike the Cache Components staged path
// it has no detached validation, so the render is the only work to cancel.
const
a
bortSignal
=
const
requestA
bortSignal
=
process
.
env
.
__NEXT_DEV_SERVER
&&
renderOpts
.
experimental
.
serverComponentsHmrCancellation
===
true
&&
requestStore
.
isHmrRefresh
===
true
&&
...
...
@@ -884,7 +884,7 @@ async function generateDynamicFlightRenderResult(
temporaryReferences
:
options
?.
temporaryReferences
,
filterStackFrame
,
debugChannel
:
debugChannel
?.
serverSide
,
signal
:
a
bortSignal
,
signal
:
requestA
bortSignal
,
}
)
...
...
@@ -920,7 +920,7 @@ async function generateDynamicFlightRenderResult(
temporaryReferences
:
options
?.
temporaryReferences
,
filterStackFrame
,
debugChannel
:
debugChannel
?.
serverSide
,
signal
:
a
bortSignal
,
signal
:
requestA
bortSignal
,
}
)
...
...
@@ -1415,7 +1415,7 @@ async function generateDynamicFlightRenderResultWithStagesInDev(
// cancel today. The response-close signal itself is general, so this could
// later be relaxed to also cover a browser stop or a devtools "cancel
// render" button.
const
a
bortSignal
=
const
requestA
bortSignal
=
renderOpts
.
experimental
.
serverComponentsHmrCancellation
===
true
&&
initialRequestStore
.
isHmrRefresh
===
true
&&
isNodeNextResponse
(
ctx
.
res
)
...
...
@@ -1436,7 +1436,7 @@ async function generateDynamicFlightRenderResultWithStagesInDev(
type
:
'prefetched-client'
,
prefetchStage
,
},
a
bortSignal
,
requestA
bortSignal
,
})
stream
=
result
.
stream
debugChannel
=
result
.
debugChannel
...
...
@@ -3520,8 +3520,8 @@ async function renderToStream(
navigationKind: {
type: 'initial-load',
},
//
The initial load has no request-abort signal to tear it down
.
a
bortSignal: undefined,
//
We currently only abort HMR refresh requests
.
requestA
bortSignal: undefined,
})
reactServerResult = new ReactServerResult(serverStream)
...
...
@@ -4461,7 +4461,7 @@ function runDevValidationInBackground(
createRequestStore: () => RequestStore,
getPayload: (requestStore: RequestStore) => Promise<RSCPayload>,
onError: (error: unknown) => void,
a
bortSignal: AbortSignal | undefined
requestA
bortSignal: AbortSignal | undefined
): void {
void consoleAsyncStorage
.run({ dim: true }, async () => {
...
...
@@ -4472,7 +4472,7 @@ function runDevValidationInBackground(
// re-rendering and analyzing it would only waste server work. In-flight
// `
'use cache'
` fills are left running (we don't await `
cacheReady
`
// below).
if (
a
bortSignal?.aborted) {
if (
requestA
bortSignal?.aborted) {
logValidationAborted(ctx)
return
}
...
...
@@ -4511,7 +4511,7 @@ function runDevValidationInBackground(
createRequestStore,
getPayload,
onError,
a
bortSignal
requestA
bortSignal
)
// If we need to do multiple renders, do them in parallel.
...
...
@@ -4536,7 +4536,7 @@ function runDevValidationInBackground(
// The request may have been aborted while we prepared the validation
// inputs above (which can itself render). Skip validation before it
// begins rather than run it for a discarded request.
if (
a
bortSignal?.aborted) {
if (
requestA
bortSignal?.aborted) {
logValidationAborted(ctx)
return
}
...
...
@@ -4548,7 +4548,7 @@ function runDevValidationInBackground(
ctx,
fallbackRouteParams,
devRenderDidError,
a
bortSignal
requestA
bortSignal
)
})
// The catch keeps a failed render, or anything thrown inside validation,
...
...
@@ -4557,7 +4557,7 @@ function runDevValidationInBackground(
// If this request was aborted, its render and detached validation are
// being torn down and their result discarded. We don't want to log these
// errors (including the abort signal reason itself).
if (
a
bortSignal?.aborted) {
if (
requestA
bortSignal?.aborted) {
return
}
console.error(
...
...
@@ -4624,7 +4624,7 @@ async function prepareValidationInputs(
createRequestStore: () => RequestStore,
getPayload: (requestStore: RequestStore) => Promise<RSCPayload>,
onError: (error: unknown) => void,
a
bortSignal: AbortSignal | undefined
requestA
bortSignal: AbortSignal | undefined
): Promise<PrepareValidationInputsResult> {
// Check if we can re-use the main render for validation.
let inputsFromNavigation: DevValidationInputs | null
...
...
@@ -4654,7 +4654,7 @@ async function prepareValidationInputs(
getPayload,
onError,
inputsFromNavigation,
a
bortSignal
requestA
bortSignal
)
} else {
return prepareValidationInputsInLegacyPrefetching(
...
...
@@ -4664,7 +4664,7 @@ async function prepareValidationInputs(
getPayload,
onError,
inputsFromNavigation,
a
bortSignal
requestA
bortSignal
)
}
}
...
...
@@ -4678,7 +4678,7 @@ async function prepareValidationInputsInPartialPrefetching(
getPayload: (requestStore: RequestStore) => Promise<RSCPayload>,
onError: (error: unknown) => void,
inputsFromNavigation: DevValidationInputs | null,
a
bortSignal: AbortSignal | undefined
requestA
bortSignal: AbortSignal | undefined
): Promise<PrepareValidationInputsResult> {
const loaderTree = ctx.componentMod.routeModule.userland.loaderTree
const needsInstantValidation =
...
...
@@ -4701,7 +4701,7 @@ async function prepareValidationInputsInPartialPrefetching(
onError,
prerenderResumeDataCache,
shouldRenderWithAppShell,
a
bortSignal
requestA
bortSignal
)
if (forwardErrorsFromWarmRender(inputs, ctx)) {
return VALIDATION_BAILOUT
...
...
@@ -4716,7 +4716,7 @@ async function prepareValidationInputsInPartialPrefetching(
getPayload,
onError,
prerenderResumeDataCache,
a
bortSignal
requestA
bortSignal
)
if (forwardErrorsFromWarmRender(inputs, ctx)) {
return VALIDATION_BAILOUT
...
...
@@ -4770,7 +4770,7 @@ async function prepareValidationInputsInLegacyPrefetching(
getPayload: (requestStore: RequestStore) => Promise<RSCPayload>,
onError: (error: unknown) => void,
inputsFromNavigation: DevValidationInputs | null,
a
bortSignal: AbortSignal | undefined
requestA
bortSignal: AbortSignal | undefined
): Promise<PrepareValidationInputsResult> {
const loaderTree = ctx.componentMod.routeModule.userland.loaderTree
const needsInstantValidation =
...
...
@@ -4794,7 +4794,7 @@ async function prepareValidationInputsInLegacyPrefetching(
onError,
prerenderResumeDataCache,
shouldRenderWithAppShell,
a
bortSignal
requestA
bortSignal
)
if (forwardErrorsFromWarmRender(inputs, ctx)) {
return VALIDATION_BAILOUT
...
...
@@ -4809,7 +4809,7 @@ async function prepareValidationInputsInLegacyPrefetching(
getPayload,
onError,
prerenderResumeDataCache,
a
bortSignal
requestA
bortSignal
)
if (forwardErrorsFromWarmRender(inputs, ctx)) {
return VALIDATION_BAILOUT
...
...
@@ -4988,7 +4988,7 @@ interface StagedDevRenderOptions {
// When this aborts, the staged dev render is torn down (its in-flight `
'use
// cache'
` fills keep running) and the detached validation is skipped.
// `
undefined
` runs both to completion.
a
bortSignal: AbortSignal | undefined
requestA
bortSignal: AbortSignal | undefined
}
type DevNavigationKind =
...
...
@@ -5040,7 +5040,7 @@ async function streamStagedRenderInDev({
onError
,
debugChannel
,
navigationKind
,
a
bortSignal
,
requestA
bortSignal
,
}:
StreamStagedRenderInDevOptions
):
Promise
<
{
stream
:
Readable
resultPromise
:
Promise
<
StagedDevRenderResult
>
...
...
@@ -5149,15 +5149,6 @@ async function streamStagedRenderInDev({
}
}
// The render runs to completion unless `abortSignal` fires, in which case
// React aborts the Flight render and the accumulation tears down. The first
// task starts the render in the `ShellEarlyStatic` stage and creates the
// stream (one replay for the response, one to accumulate the chunks). The
// later tasks advance the stages, settle `hadCacheMiss`, and reveal the shell
// – as soon as a cache miss is seen, or once the render reaches
// `revealAfterStage` – then advance into the dynamic stage a task later. The
// replayable stays local: the response is the only reader outside this
// function.
const
stagesAdvanced
=
runInSequentialTasks
(
()
=>
{
stageController
.
advanceStage
(
RenderStage
.
ShellEarlyStatic
)
...
...
@@ -5176,7 +5167,7 @@ async function streamStagedRenderInDev({
startTime
,
filterStackFrame
,
debugChannel
:
debugChannel
?.
serverSide
,
signal
:
a
bortSignal
,
signal
:
requestA
bortSignal
,
}
)
as
Readable
)
...
...
@@ -5186,10 +5177,9 @@ async function streamStagedRenderInDev({
accumulatedChunksPromise
:
accumulateStreamChunks
(
replayable
.
createReplayStream
(),
stageController
,
// Tear down the chunk accumulation on abort too, so `resultPromise`
// settles promptly (instead of waiting out the aborted render) and
// the detached validation can see the abort and skip.
abortSignal
??
null
// Abort accumulation as soon as the signal aborts instead of waiting
// for the stream to close.
requestAbortSignal
??
null
),
})
},
...
...
@@ -5279,7 +5269,7 @@ async function renderWithWarmCachesForValidationInDev(
onError
:
(
error
:
unknown
)
=>
void
,
prerenderResumeDataCache
:
ReturnType
<
typeof
createPrerenderResumeDataCache
>
,
shouldRenderWithAppShell
:
boolean
,
a
bortSignal
:
AbortSignal
|
undefined
requestA
bortSignal
:
AbortSignal
|
undefined
):
Promise
<
DevValidationInputs
>
{
const
{
ComponentMod
,
setReactDebugChannel
}
=
ctx
.
renderOpts
const
{
clientModules
}
=
getClientReferenceManifest
()
...
...
@@ -5329,14 +5319,14 @@ async function renderWithWarmCachesForValidationInDev(
startTime
,
filterStackFrame
,
debugChannel
:
debugChannel
?.
serverSide
,
signal
:
a
bortSignal
,
signal
:
requestA
bortSignal
,
}
)
as
Readable
return
accumulateStreamChunks
(
sourceStream
,
stageController
,
a
bortSignal
??
null
requestA
bortSignal
??
null
)
},
()
=>
stageController
.
advanceStage
(
RenderStage
.
ShellStatic
),
...
...
@@ -5374,7 +5364,7 @@ async function prerenderWithWarmCachesForStaticValidationInDev(
getPayload
:
(
requestStore
:
RequestStore
)
=>
Promise
<
RSCPayload
>
,
onError
:
(
error
:
unknown
)
=>
void
,
prerenderResumeDataCache
:
ReturnType
<
typeof
createPrerenderResumeDataCache
>
,
a
bortSignal
:
AbortSignal
|
undefined
requestA
bortSignal
:
AbortSignal
|
undefined
):
Promise
<
DevValidationInputs
>
{
const
{
ComponentMod
,
setReactDebugChannel
}
=
ctx
.
renderOpts
const
{
clientModules
}
=
getClientReferenceManifest
()
...
...
@@ -5385,10 +5375,8 @@ async function prerenderWithWarmCachesForStaticValidationInDev(
const
finalReactController
=
new
AbortController
()
const
finalDataController
=
new
AbortController
()
// Aborting `finalReactController` (the prerender's own controller) on the
// signal tears the render down the same way its runtime-stage abort does.
if
(
abortSignal
)
{
abortWhenSignalAborts
(
abortSignal
,
finalReactController
)
if
(
requestAbortSignal
)
{
abortWhenSignalAborts
(
requestAbortSignal
,
finalReactController
)
}
const
stageController
=
new
StagedRenderingController
({
...
...
@@ -5551,7 +5539,7 @@ async function stagedRenderWithCachesInDev({
fallbackRouteParams
,
getDevRenderDidError
,
navigationKind
,
a
bortSignal
,
requestA
bortSignal
,
}:
StagedRenderWithCachesInDevOptions
):
Promise
<
{
stream
:
Readable
debugChannel
:
NodeDebugChannelPair
|
undefined
...
...
@@ -5590,7 +5578,7 @@ async function stagedRenderWithCachesInDev({
onError
,
debugChannel
,
navigationKind
,
a
bortSignal
,
requestA
bortSignal
,
})
if
(
shouldValidate
)
{
...
...
@@ -5608,7 +5596,7 @@ async function stagedRenderWithCachesInDev({
createRequestStore
,
getPayload
,
onError
,
a
bortSignal
requestA
bortSignal
)
}
else
{
logValidationSkipped
(
ctx
)
...
...
@@ -6060,7 +6048,7 @@ async function runValidationInDevImpl(
ctx
:
AppRenderContext
,
fallbackRouteParams
:
OpaqueFallbackRouteParams
|
null
,
devRenderDidError
:
boolean
,
a
bortSignal
:
AbortSignal
|
undefined
requestA
bortSignal
:
AbortSignal
|
undefined
):
Promise
<
void
>
{
const
{
componentMod
:
ComponentMod
,
getDynamicParamFromSegment
}
=
ctx
const
loaderTree
=
ComponentMod
.
routeModule
.
userland
.
loaderTree
...
...
@@ -6121,7 +6109,7 @@ async function runValidationInDevImpl(
//================================
{
// The request may have been aborted during the client module warmup above.
if
(
a
bortSignal
?.
aborted
)
{
if
(
requestA
bortSignal
?.
aborted
)
{
return
}
...
...
@@ -6143,7 +6131,7 @@ async function runValidationInDevImpl(
// The request was aborted while this validation render ran, so its result
// is being discarded. Don't surface its validation errors: they're for a
// render that won't be shown.
if
(
a
bortSignal
?.
aborted
)
{
if
(
requestA
bortSignal
?.
aborted
)
{
return
}
if
(
result
.
length
>
0
)
{
...
...
@@ -6177,7 +6165,7 @@ async function runValidationInDevImpl(
// The request was aborted while this render ran; don't surface its stale
// validation errors: they're for a render that won't be shown.
if
(
a
bortSignal
?.
aborted
)
{
if
(
requestA
bortSignal
?.
aborted
)
{
return
}
if
(
result
.
length
>
0
)
{
...
...
packages/next/src/server/app-render/stream-ops.node.ts
View file @
ea1c09a2
...
...
@@ -551,8 +551,9 @@ export function renderToNodeFlightStream(
// `renderToPipeableStream` has no `signal` option (unlike the Web
// `renderToReadableStream`), so pull `signal` out of the options and abort
// the returned pipeable ourselves when it fires. The listener is removed once
// the passthrough closes.
// the returned pipeable ourselves when it fires. We drop the listener when
// the passthrough closes so a finished render's `pipeable` isn't retained by
// the request signal, which can outlive it.
const
{
signal
,
...
renderOptions
}
=
opts
??
{}
const
pt
=
new
PassThrough
()
...
...
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