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
aef7c344
Commit
aef7c344
authored
Dec 08, 2025
by
Jiachi Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prototyping
parent
17257e64
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
425 additions
and
129 deletions
+425
-129
dynamic-rendering.ts
packages/next/src/server/app-render/dynamic-rendering.ts
+20
-1
profiling-suspense.tsx
packages/next/src/server/app-render/profiling-suspense.tsx
+18
-55
suspense-boundary-collector.ts
...next/src/server/app-render/suspense-boundary-collector.ts
+125
-45
suspense-boundary-injector.tsx
...next/src/server/app-render/suspense-boundary-injector.tsx
+182
-22
connection.ts
packages/next/src/server/request/connection.ts
+1
-1
cookies.ts
packages/next/src/server/request/cookies.ts
+1
-1
draft-mode.ts
packages/next/src/server/request/draft-mode.ts
+1
-1
headers.ts
packages/next/src/server/request/headers.ts
+1
-1
react.ts
...t/src/server/route-modules/app-page/vendored/rsc/react.ts
+1
-1
react.ts
...t/src/server/route-modules/app-page/vendored/ssr/react.ts
+1
-1
page.tsx
test/e2e/app-dir/suspense-profiling/app/dynamic/page.tsx
+74
-0
No files found.
packages/next/src/server/app-render/dynamic-rendering.ts
View file @
aef7c344
...
...
@@ -49,6 +49,7 @@ import {
import
{
scheduleOnNextTick
}
from
'../../lib/scheduler'
import
{
BailoutToCSRError
}
from
'../../shared/lib/lazy-dynamic/bailout-to-csr'
import
{
InvariantError
}
from
'../../shared/lib/invariant-error'
import
{
trackDynamicAPIAccess
}
from
'./suspense-boundary-collector'
const
hasPostpone
=
typeof
React
.
unstable_postpone
===
'function'
...
...
@@ -224,7 +225,10 @@ export function throwToInterruptStaticGeneration(
*
* @internal
*/
export
function
trackDynamicDataInDynamicRender
(
workUnitStore
:
WorkUnitStore
)
{
export
function
trackDynamicDataInDynamicRender
(
workUnitStore
:
WorkUnitStore
,
expression
?:
string
)
{
switch
(
workUnitStore
.
type
)
{
case
'cache'
:
case
'unstable-cache'
:
...
...
@@ -246,6 +250,14 @@ export function trackDynamicDataInDynamicRender(workUnitStore: WorkUnitStore) {
if
(
process
.
env
.
NODE_ENV
!==
'production'
)
{
workUnitStore
.
usedDynamic
=
true
}
// Track for suspense profiling
if
(
expression
)
{
const
ownerStack
=
process
.
env
.
NODE_ENV
!==
'production'
&&
React
.
captureOwnerStack
?
React
.
captureOwnerStack
()
:
null
trackDynamicAPIAccess
(
expression
,
ownerStack
)
}
break
default
:
workUnitStore
satisfies
never
...
...
@@ -368,6 +380,13 @@ export function postponeWithTracking(
})
}
// Track for suspense profiling
const
ownerStack
=
process
.
env
.
NODE_ENV
!==
'production'
&&
React
.
captureOwnerStack
?
React
.
captureOwnerStack
()
:
null
trackDynamicAPIAccess
(
expression
,
ownerStack
)
React
.
unstable_postpone
(
createPostponeReason
(
route
,
expression
))
}
...
...
packages/next/src/server/app-render/profiling-suspense.tsx
View file @
aef7c344
import
type
{
ComponentProps
,
ReactNode
,
ComponentType
}
from
'react'
import
{
registerSuspenseBoundary
,
pushSuspenseBoundary
,
popSuspenseBoundary
,
type
SuspenseBoundarySource
,
}
from
'./suspense-boundary-collector'
import
{
registerSuspenseBoundary
}
from
'./suspense-boundary-collector'
type
SuspenseProps
=
ComponentProps
<
typeof
import
(
'react'
).
Suspense
>
interface
ProfilingSuspenseProps
extends
SuspenseProps
{
__source
?:
SuspenseBoundarySource
}
// Wrapper component to track boundary nesting
function
SuspenseBoundaryTracker
({
boundaryId
,
children
,
}:
{
boundaryId
:
string
children
:
ReactNode
})
{
// Push this boundary onto the stack when rendering children
// This allows us to track parent-child relationships
pushSuspenseBoundary
(
boundaryId
)
// The pop happens after children render due to React's depth-first rendering
// We use a trick: wrap children in a component that pops on render
return
(
<>
{
children
}
<
SuspenseBoundaryTrackerEnd
boundaryId=
{
boundaryId
}
/>
</>
)
}
// This component renders at the end of the boundary's children
// and pops the boundary from the stack
function
SuspenseBoundaryTrackerEnd
({
boundaryId
:
_boundaryId
,
}:
{
boundaryId
:
string
})
{
popSuspenseBoundary
()
return
null
interface
ReactWithOwnerStack
{
captureOwnerStack
?:
()
=>
string
|
null
}
export
function
createProfilingSuspense
(
OriginalSuspense
:
ComponentType
<
SuspenseProps
>
):
ComponentType
<
ProfilingSuspenseProps
>
{
function
ProfilingSuspense
(
props
:
ProfilingSuspenseProps
):
ReactNode
{
const
{
children
,
fallback
,
__source
,
...
rest
}
=
props
OriginalSuspense
:
ComponentType
<
SuspenseProps
>
,
React
:
ReactWithOwnerStack
):
ComponentType
<
SuspenseProps
>
{
function
ProfilingSuspense
(
props
:
SuspenseProps
):
ReactNode
{
const
{
children
,
fallback
,
...
rest
}
=
props
// Capture owner stack in dev mode
const
ownerStack
=
process
.
env
.
NODE_ENV
!==
'production'
&&
typeof
React
?.
captureOwnerStack
===
'function'
?
React
.
captureOwnerStack
()
:
null
// Register this boundary and get its unique ID
const
boundaryId
=
registerSuspenseBoundary
(
__source
||
null
)
const
boundaryId
=
registerSuspenseBoundary
(
ownerStack
)
// If no boundary ID (collector not active), render original
if
(
!
boundaryId
)
{
...
...
@@ -63,13 +33,6 @@ export function createProfilingSuspense(
)
}
// Wrap children to track nesting
const
trackedChildren
=
(
<
SuspenseBoundaryTracker
boundaryId=
{
boundaryId
}
>
{
children
}
</
SuspenseBoundaryTracker
>
)
return
(
<
OriginalSuspense
fallback=
{
...
...
@@ -91,7 +54,7 @@ export function createProfilingSuspense(
data
-
suspense
-
state=
"content"
hidden
/>
{
trackedC
hildren
}
{
c
hildren
}
</
OriginalSuspense
>
)
}
...
...
@@ -99,5 +62,5 @@ export function createProfilingSuspense(
// Preserve display name for debugging
ProfilingSuspense
.
displayName
=
'Suspense'
return
ProfilingSuspense
as
ComponentType
<
ProfilingSuspenseProps
>
return
ProfilingSuspense
}
packages/next/src/server/app-render/suspense-boundary-collector.ts
View file @
aef7c344
import
type
{
AsyncLocalStorage
}
from
'async_hooks'
import
{
createAsyncLocalStorage
}
from
'./async-local-storage'
export
interface
SuspenseBoundarySource
{
fileName
:
string
lineNumber
:
number
columnNumber
:
number
export
interface
StackFrame
{
componentName
:
string
fileName
:
string
|
null
lineNumber
:
number
|
null
columnNumber
:
number
|
null
}
export
interface
DynamicAPIAccess
{
expression
:
string
// e.g., "cookies", "headers", "connection"
frames
:
StackFrame
[]
// owner stack at the point of call
}
export
interface
SuspenseBoundaryInfo
{
id
:
string
source
:
SuspenseBoundarySource
|
null
parentId
:
string
|
null
children
:
string
[]
frames
:
StackFrame
[]
}
export
interface
SuspenseBoundaryCollectorStore
{
boundaries
:
Map
<
string
,
SuspenseBoundaryInfo
>
idCounter
:
number
parentStack
:
string
[]
// Track dynamic API accesses that occurred during the render
dynamicAccesses
:
DynamicAPIAccess
[]
}
// Use globalThis to ensure singleton across module duplications (vendored React bundles separately)
const
globalKey
=
'__NEXT_SUSPENSE_BOUNDARY_COLLECTOR_STORAGE__'
function
getOrCreateStorage
():
AsyncLocalStorage
<
SuspenseBoundaryCollectorStore
>
{
const
g
=
globalThis
as
any
if
(
!
g
[
globalKey
])
{
g
[
globalKey
]
=
createAsyncLocalStorage
<
SuspenseBoundaryCollectorStore
>
()
}
return
g
[
globalKey
]
}
export
const
suspenseBoundaryCollectorStorage
=
createAsyncLocalStorage
<
SuspenseBoundaryCollectorStore
>
()
export
const
suspenseBoundaryCollectorStorage
=
getOrCreateStorage
()
export
function
createSuspenseBoundaryCollector
():
SuspenseBoundaryCollectorStore
{
return
{
boundaries
:
new
Map
(),
idCounter
:
0
,
parentStack
:
[],
dynamicAccesses
:
[],
}
}
export
function
registerSuspenseBoundary
(
source
:
SuspenseBoundarySource
|
null
):
string
{
/**
* Track a dynamic API access (e.g., cookies(), headers(), connection())
* This is called from dynamic-rendering.ts when a dynamic API is used
*/
export
function
trackDynamicAPIAccess
(
expression
:
string
,
ownerStack
:
string
|
null
):
void
{
const
store
=
suspenseBoundaryCollectorStorage
.
getStore
()
if
(
!
store
)
{
return
''
return
}
const
id
=
`suspense-
${
store
.
idCounter
++
}
`
const
parentId
=
store
.
parentStack
[
store
.
parentStack
.
length
-
1
]
||
null
// Register this boundary
store
.
boundaries
.
set
(
id
,
{
id
,
source
,
parentId
,
children
:
[],
store
.
dynamicAccesses
.
push
({
expression
,
frames
:
parseOwnerStack
(
ownerStack
),
})
}
/**
* Parse owner stack string into structured stack frames
* Format: " at ComponentName (file:line:col)\n at Parent..."
* Or: " at ComponentName (file:line:col)"
* Or: " at file:line:col" (anonymous)
*/
function
parseOwnerStack
(
ownerStack
:
string
|
null
):
StackFrame
[]
{
if
(
!
ownerStack
)
return
[]
const
frames
:
StackFrame
[]
=
[]
const
lines
=
ownerStack
.
split
(
'
\
n'
)
for
(
const
line
of
lines
)
{
const
trimmed
=
line
.
trim
()
if
(
!
trimmed
.
startsWith
(
'at '
))
continue
// Add to parent's children list
if
(
parentId
)
{
const
parent
=
store
.
boundaries
.
get
(
parentId
)
if
(
parent
)
{
parent
.
children
.
push
(
id
)
// Try to match "at ComponentName (file:line:col)"
const
namedMatch
=
trimmed
.
match
(
/^at
\s
+
([^\s
(
]
+
)\s
+
\((
.+
)
:
(\d
+
)
:
(\d
+
)\)
$/
)
if
(
namedMatch
)
{
frames
.
push
({
componentName
:
namedMatch
[
1
],
fileName
:
namedMatch
[
2
],
lineNumber
:
parseInt
(
namedMatch
[
3
],
10
),
columnNumber
:
parseInt
(
namedMatch
[
4
],
10
),
})
continue
}
}
return
id
}
// Try to match "at ComponentName (file:line)"
const
namedNoColMatch
=
trimmed
.
match
(
/^at
\s
+
([^\s
(
]
+
)\s
+
\((
.+
)
:
(\d
+
)\)
$/
)
if
(
namedNoColMatch
)
{
frames
.
push
({
componentName
:
namedNoColMatch
[
1
],
fileName
:
namedNoColMatch
[
2
],
lineNumber
:
parseInt
(
namedNoColMatch
[
3
],
10
),
columnNumber
:
null
,
})
continue
}
export
function
pushSuspenseBoundary
(
id
:
string
):
void
{
const
store
=
suspenseBoundaryCollectorStorage
.
getStore
()
if
(
store
&&
id
)
{
store
.
parentStack
.
push
(
id
)
// Try to match "at file:line:col" (anonymous)
const
anonMatch
=
trimmed
.
match
(
/^at
\s
+
(
.+
)
:
(\d
+
)
:
(\d
+
)
$/
)
if
(
anonMatch
)
{
frames
.
push
({
componentName
:
'<anonymous>'
,
fileName
:
anonMatch
[
1
],
lineNumber
:
parseInt
(
anonMatch
[
2
],
10
),
columnNumber
:
parseInt
(
anonMatch
[
3
],
10
),
})
continue
}
// Try to match "at ComponentName" (no file info)
const
nameOnlyMatch
=
trimmed
.
match
(
/^at
\s
+
([^\s
(
]
+
)
$/
)
if
(
nameOnlyMatch
)
{
frames
.
push
({
componentName
:
nameOnlyMatch
[
1
],
fileName
:
null
,
lineNumber
:
null
,
columnNumber
:
null
,
})
continue
}
}
return
frames
}
export
function
popSuspenseBoundary
():
void
{
export
function
registerSuspenseBoundary
(
ownerStack
:
string
|
null
):
string
{
const
store
=
suspenseBoundaryCollectorStorage
.
getStore
()
if
(
store
)
{
store
.
parentStack
.
pop
()
if
(
!
store
)
{
return
''
}
const
id
=
`suspense-
${
store
.
idCounter
++
}
`
const
frames
=
parseOwnerStack
(
ownerStack
)
store
.
boundaries
.
set
(
id
,
{
id
,
frames
,
})
return
id
}
export
function
getSuspenseBoundaries
():
SuspenseBoundaryInfo
[]
{
...
...
@@ -82,10 +162,10 @@ export function getSuspenseBoundaries(): SuspenseBoundaryInfo[] {
return
Array
.
from
(
store
.
boundaries
.
values
())
}
export
function
serializeSuspenseBoundaries
():
string
{
const
boundaries
=
getSuspenseBoundaries
()
return
JSON
.
stringify
(
{
boundaries
,
timestamp
:
Date
.
now
(),
})
export
function
getDynamicAccesses
():
DynamicAPIAccess
[]
{
const
store
=
suspenseBoundaryCollectorStorage
.
getStore
()
if
(
!
store
)
{
return
[]
}
return
store
.
dynamicAccesses
}
packages/next/src/server/app-render/suspense-boundary-injector.tsx
View file @
aef7c344
import
React
from
'react'
import
{
getSuspenseBoundaries
,
getDynamicAccesses
,
type
SuspenseBoundaryInfo
,
type
DynamicAPIAccess
,
}
from
'./suspense-boundary-collector'
export
interface
SuspenseBoundaryData
{
boundaries
:
SuspenseBoundaryInfo
[]
dynamicAccesses
:
DynamicAPIAccess
[]
timestamp
:
number
}
export
function
getSuspenseBoundaryData
():
SuspenseBoundaryData
{
return
{
boundaries
:
getSuspenseBoundaries
(),
dynamicAccesses
:
getDynamicAccesses
(),
timestamp
:
Date
.
now
(),
}
}
export
function
SuspenseBoundaryScript
():
React
.
ReactNode
{
const
data
=
getSuspenseBoundaryData
()
const
panelScript
=
`
(function() {
if (typeof window === 'undefined') return;
// Only inject if there are boundaries to report
// (boundaries are only collected when suspense profiling is enabled)
if
(
data
.
boundaries
.
length
===
0
)
{
return
null
}
function createPanel() {
const script = document.getElementById('__NEXT_SUSPENSE_BOUNDARIES__');
if (!script) return;
return
(
<
script
id=
"__NEXT_SUSPENSE_BOUNDARIES__"
type=
"application/json"
dangerouslySetInnerHTML=
{
{
__html
:
JSON
.
stringify
(
data
),
}
}
/>
)
}
let data;
try {
data = JSON.parse(script.textContent || '{}');
} catch (e) {
return;
}
export
function
serializeSuspenseBoundaryScript
():
string
{
const
data
=
getSuspenseBoundaryData
()
const container = document.createElement('div');
container.id = '__next_suspense_profiler__';
document.body.appendChild(container);
// Track expanded nodes by path
window.__sp = {
isOpen: false,
expanded: {},
toggle: function(path) {
window.__sp.expanded[path] = !window.__sp.expanded[path];
render();
},
open: function() {
window.__sp.isOpen = true;
render();
},
close: function() {
window.__sp.isOpen = false;
render();
}
};
// Build tree from boundaries and dynamic accesses
function buildTree(boundaries, dynamicAccesses) {
var root = { name: 'Root', children: {}, boundaries: [], apis: [] };
// Add boundaries to tree
boundaries.forEach(function(b) {
if (!b.frames.length) return;
// Reverse frames: from root to leaf
var path = b.frames.slice().reverse();
var node = root;
path.forEach(function(frame) {
var name = frame.componentName;
if (!node.children[name]) {
node.children[name] = { name: name, children: {}, boundaries: [], apis: [], frame: frame };
}
node = node.children[name];
});
node.boundaries.push(b);
});
// Add dynamic APIs to tree
dynamicAccesses.forEach(function(api) {
if (!api.frames.length) return;
var path = api.frames.slice().reverse();
var node = root;
path.forEach(function(frame) {
var name = frame.componentName;
if (!node.children[name]) {
node.children[name] = { name: name, children: {}, boundaries: [], apis: [], frame: frame };
}
node = node.children[name];
});
node.apis.push(api);
});
return root;
}
function renderNode(node, depth, path) {
var sp = window.__sp;
var childKeys = Object.keys(node.children);
var hasChildren = childKeys.length > 0;
var isExpanded = sp.expanded[path] !== false; // Default expanded
var indent = depth * 16;
var html = '';
if (depth > 0) {
var hasSuspense = node.boundaries.length > 0;
var hasApis = node.apis.length > 0;
html += '<div style="border-bottom:1px solid #f5f5f5;">';
html += '<div onclick="window.__sp.toggle(\\'' + path + '\\')" style="padding:8px 12px 8px ' + (12 + indent) + 'px;cursor:pointer;display:flex;align-items:center;gap:6px;">';
if
(
data
.
boundaries
.
length
===
0
)
{
return
''
if (hasChildren) {
html += '<span style="color:#999;font-size:9px;width:10px;">' + (isExpanded ? '▼' : '▶') + '</span>';
} else {
html += '<span style="width:10px;"></span>';
}
html += '<span style="color:#1a1a1a;">' + node.name + '</span>';
if (hasSuspense) {
html += '<span style="background:#e8e8e8;color:#666;padding:1px 6px;border-radius:3px;font-size:10px;">suspense</span>';
}
if (hasApis) {
var apiNames = [];
node.apis.forEach(function(a) { if (apiNames.indexOf(a.expression) === -1) apiNames.push(a.expression); });
html += '<span style="color:#888;font-size:11px;margin-left:auto;">' + apiNames.join(', ') + '</span>';
}
html += '</div></div>';
}
if (isExpanded && hasChildren) {
childKeys.forEach(function(key) {
html += renderNode(node.children[key], depth + 1, path + '/' + key);
});
}
return html;
}
function render() {
var boundaries = data.boundaries || [];
var dynamicAccesses = data.dynamicAccesses || [];
var sp = window.__sp;
if (sp.isOpen) {
var tree = buildTree(boundaries, dynamicAccesses);
var treeHtml = '';
Object.keys(tree.children).forEach(function(key) {
treeHtml += renderNode(tree.children[key], 1, key);
});
container.innerHTML = '<div style="position:fixed;bottom:20px;right:20px;z-index:99999;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif;font-size:13px;">' +
'<div style="background:#fff;color:#1a1a1a;border:1px solid #e0e0e0;border-radius:8px;width:360px;max-height:450px;overflow:hidden;display:flex;flex-direction:column;box-shadow:0 4px 12px rgba(0,0,0,0.1);">' +
'<div style="padding:12px 16px;border-bottom:1px solid #e0e0e0;display:flex;justify-content:space-between;align-items:center;">' +
'<span style="font-weight:600;color:#1a1a1a;">Component Tree</span>' +
'<button onclick="window.__sp.close()" style="background:none;border:none;color:#666;cursor:pointer;font-size:18px;line-height:1;padding:0 4px;">×</button>' +
'</div>' +
'<div style="overflow:auto;flex:1;">' +
(treeHtml || '<div style="padding:16px;color:#888;">No boundaries detected</div>') +
'</div>' +
'</div>' +
'</div>';
} else {
var hasDynamic = dynamicAccesses.length > 0;
container.innerHTML = '<div style="position:fixed;bottom:20px;right:20px;z-index:99999;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif;font-size:13px;">' +
'<button onclick="window.__sp.open()" style="background:#fff;color:#1a1a1a;border:1px solid #e0e0e0;border-radius:6px;padding:8px 14px;cursor:pointer;display:flex;align-items:center;gap:8px;box-shadow:0 2px 8px rgba(0,0,0,0.08);">' +
'<span>⏳ ' + boundaries.length + '</span>' +
(hasDynamic ? '<span style="color:#666;">' + dynamicAccesses.length + ' dynamic</span>' : '') +
'</button>' +
'</div>';
}
}
render();
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', createPanel);
} else {
createPanel();
}
})();
`
export
function
SuspenseBoundaryScript
():
React
.
ReactNode
{
const
data
=
getSuspenseBoundaryData
()
return
`<script id="__NEXT_SUSPENSE_BOUNDARIES__" type="application/json">
${
JSON
.
stringify
(
data
)}
</script>`
return
(
<>
<
script
id=
"__NEXT_SUSPENSE_BOUNDARIES__"
type=
"application/json"
dangerouslySetInnerHTML=
{
{
__html
:
JSON
.
stringify
(
data
),
}
}
/>
<
script
dangerouslySetInnerHTML=
{
{
__html
:
panelScript
,
}
}
/>
</>
)
}
packages/next/src/server/request/connection.ts
View file @
aef7c344
...
...
@@ -101,7 +101,7 @@ export function connection(): Promise<void> {
workUnitStore
)
case
'request'
:
trackDynamicDataInDynamicRender
(
workUnitStore
)
trackDynamicDataInDynamicRender
(
workUnitStore
,
callingExpression
)
if
(
process
.
env
.
NODE_ENV
===
'development'
)
{
// Semantically we only need the dev tracking when running in `next dev`
// but since you would never use next dev with production NODE_ENV we use this
...
...
packages/next/src/server/request/cookies.ts
View file @
aef7c344
...
...
@@ -106,7 +106,7 @@ export function cookies(): Promise<ReadonlyRequestCookies> {
// so we don't need an additional delay here.
return
makeUntrackedCookies
(
workUnitStore
.
cookies
)
case
'request'
:
trackDynamicDataInDynamicRender
(
workUnitStore
)
trackDynamicDataInDynamicRender
(
workUnitStore
,
callingExpression
)
let
underlyingCookies
:
ReadonlyRequestCookies
...
...
packages/next/src/server/request/draft-mode.ts
View file @
aef7c344
...
...
@@ -238,7 +238,7 @@ function trackDynamicDraftMode(expression: string, constructorOpt: Function) {
throw
err
case
'request'
:
trackDynamicDataInDynamicRender
(
workUnitStore
)
trackDynamicDataInDynamicRender
(
workUnitStore
,
expression
)
break
default
:
workUnitStore
satisfies
never
...
...
packages/next/src/server/request/headers.ts
View file @
aef7c344
...
...
@@ -132,7 +132,7 @@ export function headers(): Promise<ReadonlyHeaders> {
// so we don't need an additional delay here.
return
makeUntrackedHeaders
(
workUnitStore
.
headers
)
case
'request'
:
trackDynamicDataInDynamicRender
(
workUnitStore
)
trackDynamicDataInDynamicRender
(
workUnitStore
,
callingExpression
)
if
(
process
.
env
.
NODE_ENV
===
'development'
)
{
// Semantically we only need the dev tracking when running in `next dev`
...
...
packages/next/src/server/route-modules/app-page/vendored/rsc/react.ts
View file @
aef7c344
...
...
@@ -8,5 +8,5 @@ const ReactRSC = (
// The wrapper checks at render time if the collector is active.
// If not, it renders the original Suspense without markers.
module
.
exports
=
Object
.
assign
({},
ReactRSC
,
{
Suspense
:
createProfilingSuspense
(
ReactRSC
.
Suspense
),
Suspense
:
createProfilingSuspense
(
ReactRSC
.
Suspense
,
ReactRSC
),
})
packages/next/src/server/route-modules/app-page/vendored/ssr/react.ts
View file @
aef7c344
...
...
@@ -8,5 +8,5 @@ const ReactSSR = (
// The wrapper checks at render time if the collector is active.
// If not, it renders the original Suspense without markers.
module
.
exports
=
Object
.
assign
({},
ReactSSR
,
{
Suspense
:
createProfilingSuspense
(
ReactSSR
.
Suspense
),
Suspense
:
createProfilingSuspense
(
ReactSSR
.
Suspense
,
ReactSSR
),
})
test/e2e/app-dir/suspense-profiling/app/dynamic/page.tsx
0 → 100644
View file @
aef7c344
import
{
Suspense
}
from
'react'
import
{
cookies
,
headers
}
from
'next/headers'
// Component that uses cookies - triggers dynamic API
async
function
CookieCounter
()
{
const
cookieStore
=
await
cookies
()
const
allCookies
=
cookieStore
.
getAll
()
return
(
<
div
data
-
testid=
"cookie-counter"
>
Cookie count:
{
allCookies
.
length
}
</
div
>
)
}
// Component that uses headers - triggers dynamic API
async
function
HeaderInfo
()
{
const
headersList
=
await
headers
()
const
userAgent
=
headersList
.
get
(
'user-agent'
)
||
'Unknown'
return
(
<
div
data
-
testid=
"header-info"
>
User Agent:
{
userAgent
.
slice
(
0
,
50
)
}
...
</
div
>
)
}
// Regular async component (no dynamic API)
async
function
SlowComponent
({
id
,
delay
}:
{
id
:
string
;
delay
:
number
})
{
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
delay
))
return
<
div
data
-
testid=
{
`content-${id}`
}
>
Content
{
id
}
loaded
</
div
>
}
// Wrapper components to make boundaries identifiable
function
CookieSection
()
{
return
(
<
Suspense
fallback=
{
<
div
data
-
testid=
"cookies-loading"
>
Loading cookies...
</
div
>
}
>
<
CookieCounter
/>
</
Suspense
>
)
}
function
HeaderSection
()
{
return
(
<
Suspense
fallback=
{
<
div
data
-
testid=
"headers-loading"
>
Loading headers...
</
div
>
}
>
<
HeaderInfo
/>
</
Suspense
>
)
}
function
RegularSection
()
{
return
(
<
Suspense
fallback=
{
<
div
data
-
testid=
"regular-loading"
>
Loading regular...
</
div
>
}
>
<
SlowComponent
id=
"regular"
delay=
{
100
}
/>
</
Suspense
>
)
}
export
default
function
DynamicPage
()
{
return
(
<
div
data
-
testid=
"dynamic-page-root"
>
<
h1
>
Dynamic API Test
</
h1
>
<
section
>
<
h2
>
Dynamic APIs (will opt out of static rendering)
</
h2
>
<
CookieSection
/>
<
HeaderSection
/>
</
section
>
<
section
>
<
h2
>
Regular Async (no dynamic API)
</
h2
>
<
RegularSection
/>
</
section
>
</
div
>
)
}
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