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
a947fb46
Commit
a947fb46
authored
Feb 24, 2026
by
Janka Uryga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
8af4eb18
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
118 additions
and
28 deletions
+118
-28
metadata.tsx
packages/next/src/lib/metadata/metadata.tsx
+1
-0
app-render-render-utils.ts
...ges/next/src/server/app-render/app-render-render-utils.ts
+2
-0
app-render.tsx
packages/next/src/server/app-render/app-render.tsx
+62
-26
staged-rendering.ts
packages/next/src/server/app-render/staged-rendering.ts
+1
-0
fast-set-immediate.external.ts
...ode-environment-extensions/fast-set-immediate.external.ts
+50
-2
page.tsx
...valid-dynamic-viewport-in-blocking-inside-static/page.tsx
+2
-0
No files found.
packages/next/src/lib/metadata/metadata.tsx
View file @
a947fb46
...
...
@@ -72,6 +72,7 @@ export function createMetadataComponents({
// runtime-prefetchable, defer until the Static stage so that
// prefetchable segments get a head start.
if
(
!
isRuntimePrefetchable
)
{
console
.
log
(
'metadata :: delaying viewport until static stage'
)
const
workUnitStore
=
workUnitAsyncStorage
.
getStore
()
if
(
workUnitStore
)
{
const
stagedRendering
=
getStagedRenderingController
(
workUnitStore
)
...
...
packages/next/src/server/app-render/app-render-render-utils.ts
View file @
a947fb46
...
...
@@ -31,6 +31,7 @@ export function runInSequentialTasks<R>(
let
result
:
R
ids
.
push
(
scheduleTimeout
(()
=>
{
console
.
log
(
`-----------------------------------------------------`
)
try
{
DANGEROUSLY_runPendingImmediatesAfterCurrentTask
()
result
=
first
()
...
...
@@ -57,6 +58,7 @@ export function runInSequentialTasks<R>(
ids
.
push
(
scheduleTimeout
(()
=>
{
console
.
log
(
`-----------------------------------------------------`
)
try
{
DANGEROUSLY_runPendingImmediatesAfterCurrentTask
()
fn
()
...
...
packages/next/src/server/app-render/app-render.tsx
View file @
a947fb46
...
...
@@ -242,6 +242,7 @@ import { createNodeStreamWithLateRelease } from './instant-validation/stream-uti
// NOTE: Only use this for types, access implementations via ComponentMod
import
type
*
as
InstantValidation
from
'./instant-validation/instant-validation'
import
{
createValidationBoundaryTracking
}
from
'./instant-validation/boundary-tracking'
import
{
scheduleTickAfterImmediates
}
from
'../node-environment-extensions/fast-set-immediate.external'
export
type
GetDynamicParamFromSegment
=
(
// The LoaderTree to extract the dynamic param from
...
...
@@ -3268,20 +3269,22 @@ async function renderWithRestartOnCacheMissInDev(
stream
.
cancel
()
})
scheduleTickAfterImmediates
(()
=>
{
// Late static
if
(
initialAbandonController
.
signal
.
aborted
===
true
)
{
return
}
else
if
(
cacheSignal
.
hasPendingReads
())
{
initialAbandonController
.
abort
()
}
else
{
initialStageController
.
advanceStage
(
RenderStage
.
Static
)
}
})
return
{
stream
,
accumulatedChunksPromise
,
}
},
()
=>
{
if
(
initialAbandonController
.
signal
.
aborted
===
true
)
{
return
}
else
if
(
cacheSignal
.
hasPendingReads
())
{
initialAbandonController
.
abort
()
}
else
{
initialStageController
.
advanceStage
(
RenderStage
.
Static
)
}
},
()
=>
{
if
(
initialAbandonController
.
signal
.
aborted
===
true
)
{
return
...
...
@@ -3289,15 +3292,16 @@ async function renderWithRestartOnCacheMissInDev(
initialAbandonController
.
abort
()
}
else
{
initialStageController
.
advanceStage
(
RenderStage
.
EarlyRuntime
)
}
},
()
=>
{
if
(
initialAbandonController
.
signal
.
aborted
===
true
)
{
return
}
else
if
(
cacheSignal
.
hasPendingReads
())
{
initialAbandonController
.
abort
()
}
else
{
initialStageController
.
advanceStage
(
RenderStage
.
Runtime
)
scheduleTickAfterImmediates
(()
=>
{
if
(
initialAbandonController
.
signal
.
aborted
===
true
)
{
return
}
else
if
(
cacheSignal
.
hasPendingReads
())
{
initialAbandonController
.
abort
()
}
else
{
initialStageController
.
advanceStage
(
RenderStage
.
Runtime
)
}
})
}
},
()
=>
{
...
...
@@ -3397,6 +3401,11 @@ async function renderWithRestartOnCacheMissInDev(
)
.
tee
()
scheduleTickAfterImmediates
(()
=>
{
// Static stage
finalStageController
.
advanceStage
(
RenderStage
.
Static
)
})
return
{
stream
:
streamPair
[
0
],
accumulatedChunksPromise
:
accumulateStreamChunks
(
...
...
@@ -3406,17 +3415,14 @@ async function renderWithRestartOnCacheMissInDev(
),
}
},
()
=>
{
// Static stage
finalStageController
.
advanceStage
(
RenderStage
.
Static
)
},
()
=>
{
// EarlyRuntime stage
finalStageController
.
advanceStage
(
RenderStage
.
EarlyRuntime
)
},
()
=>
{
// Runtime stage
finalStageController
.
advanceStage
(
RenderStage
.
Runtime
)
scheduleTickAfterImmediates
(()
=>
{
// Runtime stage
finalStageController
.
advanceStage
(
RenderStage
.
Runtime
)
})
},
()
=>
{
// Dynamic stage
...
...
@@ -4205,6 +4211,36 @@ async function validateInstantConfigs(
clientReferenceManifest
)
const
chunksToString
=
(
chunks
:
Uint8Array
[])
=>
Buffer
.
concat
(
chunks
.
map
((
chunk
)
=>
Buffer
.
from
(
chunk
))).
toString
(
'utf-8'
)
for
(
const
[
segmentPath
,
segmentChunks
]
of
[
[
'_head'
,
cache
.
head
!
]
as
const
,
// ...cache.segments,
])
{
console
.
log
(
'------------------------------------------'
)
console
.
log
(
segmentPath
)
console
.
log
(
'========= Static =========='
)
console
.
log
(
chunksToString
(
segmentChunks
.
chunks
[
RenderStage
.
Static
]))
console
.
log
(
'========= Runtime =========='
)
console
.
log
(
chunksToString
(
segmentChunks
.
chunks
[
RenderStage
.
Runtime
].
slice
(
segmentChunks
.
chunks
[
RenderStage
.
Static
].
length
)
)
)
console
.
log
(
'========= Dynamic =========='
)
console
.
log
(
chunksToString
(
segmentChunks
.
chunks
[
RenderStage
.
Dynamic
].
slice
(
segmentChunks
.
chunks
[
RenderStage
.
Runtime
].
length
)
)
)
console
.
log
(
'
\
n'
)
}
const
getFilepathForSegment
=
(
segmentPath
:
InstantValidation
.
SegmentPath
)
=>
treeNodes
.
get
(
segmentPath
)?.
module
?.
conventionPath
const
getCreateInstantStackForSegment
=
(
...
...
packages/next/src/server/app-render/staged-rendering.ts
View file @
a947fb46
...
...
@@ -217,6 +217,7 @@ export class StagedRenderingController {
if
(
stage
<=
this
.
currentStage
)
{
return
}
console
.
log
(
`----------------
${
RenderStage
[
stage
]}
----------------`
)
let
currentStage
=
this
.
currentStage
this
.
currentStage
=
stage
...
...
packages/next/src/server/node-environment-extensions/fast-set-immediate.external.ts
View file @
a947fb46
...
...
@@ -5,6 +5,7 @@ import { bindSnapshot } from '../app-render/async-local-storage'
type
Execution
=
{
state
:
ExecutionState
queuedImmediates
:
QueueItem
[]
queuedTicksAfterImmediates
:
AfterImmediatesQueueItem
[]
}
enum
ExecutionState
{
...
...
@@ -286,7 +287,30 @@ function performWork(execution: Execution) {
}
execution
.
state
=
ExecutionState
.
Working
const
queueItem
=
takeNextActiveQueueItem
(
execution
)
let
queueItem
=
takeNextActiveQueueItem
(
execution
)
if
(
queueItem
===
null
&&
execution
.
queuedTicksAfterImmediates
.
length
>
0
)
{
debug
?.(
`scheduler :: finished immediates, running ticks`
)
// TODO: gross hack
const
ticks
=
execution
.
queuedTicksAfterImmediates
execution
.
queuedTicksAfterImmediates
=
[]
queueItem
=
{
isCleared
:
false
,
callback
:
()
=>
{
for
(
const
tick
of
ticks
)
{
const
{
callback
}
=
tick
try
{
callback
()
}
catch
(
err
)
{
// TODO: handle errors?
console
.
error
(
'Unhandled error in tick:'
,
err
)
}
}
},
args
:
null
,
immediateObject
:
null
!
,
}
}
if
(
queueItem
===
null
)
{
debug
?.(
`scheduler :: no immediates queued, exiting`
)
...
...
@@ -298,7 +322,10 @@ function performWork(execution: Execution) {
const
{
immediateObject
,
callback
,
args
}
=
queueItem
immediateObject
[
INTERNALS
].
queueItem
=
null
// TODO: should be impossible, we're cheating
if
(
immediateObject
)
{
immediateObject
[
INTERNALS
].
queueItem
=
null
}
clearQueueItem
(
queueItem
)
// Execute the immediate.
...
...
@@ -413,6 +440,7 @@ function startCapturingImmediates(): Execution {
const
execution
:
Execution
=
{
state
:
ExecutionState
.
Waiting
,
queuedImmediates
:
[],
queuedTicksAfterImmediates
:
[],
}
currentExecution
=
execution
...
...
@@ -512,6 +540,10 @@ function clearQueueItem(originalQueueItem: QueueItem) {
queueItem
.
immediateObject
=
null
}
type
AfterImmediatesQueueItem
=
{
callback
:
()
=>
any
}
//========================================================
function
patchedNextTick
<
TArgs
extends
any
[]
>
(
...
...
@@ -789,6 +821,22 @@ class NextImmediate implements NativeImmediate {
// ==========================================
export
function
scheduleTickAfterImmediates
(
callback
:
()
=>
void
)
{
if
(
currentExecution
===
null
)
{
// TODO: check status?
throw
new
InvariantError
(
"Cannot schedule tick after immediates if immediates aren't being captured"
)
}
const
callbackWithAsyncContext
=
bindSnapshot
(
callback
)
const
queueItem
:
AfterImmediatesQueueItem
=
{
callback
:
callbackWithAsyncContext
,
}
currentExecution
.
queuedTicksAfterImmediates
.
push
(
queueItem
)
}
// ==========================================
const
debug
=
process
.
env
.
NEXT_DEBUG_IMMEDIATES
!==
'1'
?
undefined
...
...
test/e2e/app-dir/instant-validation/app/suspense-in-root/head/invalid-dynamic-viewport-in-blocking-inside-static/page.tsx
View file @
a947fb46
...
...
@@ -4,7 +4,9 @@ import { connection } from 'next/server'
export
const
unstable_instant
=
false
export
async
function
generateViewport
():
Promise
<
Viewport
>
{
console
.
log
(
'page :: generateViewport start'
)
await
connection
()
console
.
log
(
'page :: generateViewport finished'
)
return
{
themeColor
:
'aliceblue'
,
}
...
...
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