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
ae18e3db
Commit
ae18e3db
authored
Dec 09, 2025
by
Jiachi Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prompt of suggestion
parent
2de49121
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
288 additions
and
44 deletions
+288
-44
suspense-boundary-injector.tsx
...next/src/server/app-render/suspense-boundary-injector.tsx
+119
-23
page.tsx
test/e2e/app-dir/suspense-profiling/app/dynamic/page.tsx
+141
-20
layout.tsx
test/e2e/app-dir/suspense-profiling/app/layout.tsx
+28
-1
No files found.
packages/next/src/server/app-render/suspense-boundary-injector.tsx
View file @
ae18e3db
This diff is collapsed.
Click to expand it.
test/e2e/app-dir/suspense-profiling/app/dynamic/page.tsx
View file @
ae18e3db
...
...
@@ -3,9 +3,54 @@ import { cookies, headers } from 'next/headers'
import
{
connection
}
from
'next/server'
// =============================================================================
// C
ase 1: cookies() - Request-specific data (no "use cache")
// C
omponent wrappers to create depth between Suspense and dynamic API
// =============================================================================
async
function
CookieContent
()
{
function
Dashboard
({
children
}:
{
children
:
React
.
ReactNode
})
{
return
<
div
className=
"dashboard"
>
{
children
}
</
div
>
}
function
UserSection
({
children
}:
{
children
:
React
.
ReactNode
})
{
return
<
div
className=
"user-section"
>
{
children
}
</
div
>
}
function
UserProfile
({
children
}:
{
children
:
React
.
ReactNode
})
{
return
<
div
className=
"user-profile"
>
{
children
}
</
div
>
}
function
ProfileSettings
({
children
}:
{
children
:
React
.
ReactNode
})
{
return
<
div
className=
"profile-settings"
>
{
children
}
</
div
>
}
function
SettingsPanel
({
children
}:
{
children
:
React
.
ReactNode
})
{
return
<
div
className=
"settings-panel"
>
{
children
}
</
div
>
}
function
PreferencesForm
({
children
}:
{
children
:
React
.
ReactNode
})
{
return
<
div
className=
"preferences-form"
>
{
children
}
</
div
>
}
function
FormFields
({
children
}:
{
children
:
React
.
ReactNode
})
{
return
<
div
className=
"form-fields"
>
{
children
}
</
div
>
}
function
RequestHandler
({
children
}:
{
children
:
React
.
ReactNode
})
{
return
<
div
className=
"request-handler"
>
{
children
}
</
div
>
}
function
NetworkLayer
({
children
}:
{
children
:
React
.
ReactNode
})
{
return
<
div
className=
"network-layer"
>
{
children
}
</
div
>
}
function
DataProvider
({
children
}:
{
children
:
React
.
ReactNode
})
{
return
<
div
className=
"data-provider"
>
{
children
}
</
div
>
}
// =============================================================================
// Case 1: cookies() - Deep nesting (7 layers)
// Dashboard > UserSection > UserProfile > ProfileSettings > SettingsPanel > PreferencesForm > FormFields > CookieReader
// =============================================================================
async
function
CookieReader
()
{
const
cookieStore
=
await
cookies
()
const
allCookies
=
cookieStore
.
getAll
()
return
(
...
...
@@ -15,10 +60,31 @@ async function CookieContent() {
)
}
function
DeepCookieContent
()
{
return
(
<
Dashboard
>
<
UserSection
>
<
UserProfile
>
<
ProfileSettings
>
<
SettingsPanel
>
<
PreferencesForm
>
<
FormFields
>
<
CookieReader
/>
</
FormFields
>
</
PreferencesForm
>
</
SettingsPanel
>
</
ProfileSettings
>
</
UserProfile
>
</
UserSection
>
</
Dashboard
>
)
}
// =============================================================================
// Case 2: headers() - Request-specific data (no "use cache")
// Case 2: headers() - Medium nesting (3 layers)
// RequestHandler > NetworkLayer > DataProvider > HeaderReader
// =============================================================================
async
function
Header
Content
()
{
async
function
Header
Reader
()
{
const
headersList
=
await
headers
()
const
userAgent
=
headersList
.
get
(
'user-agent'
)
||
'Unknown'
return
(
...
...
@@ -28,10 +94,31 @@ async function HeaderContent() {
)
}
function
HeaderContent
()
{
return
(
<
RequestHandler
>
<
NetworkLayer
>
<
DataProvider
>
<
HeaderReader
/>
</
DataProvider
>
</
NetworkLayer
>
</
RequestHandler
>
)
}
// =============================================================================
// Case 3: connection() - Explicitly opt into dynamic rendering
// Case 3: connection() - Medium nesting (2 layers)
// ApiClient > ConnectionHandler > ConnectionReader
// =============================================================================
async
function
ConnectionContent
()
{
function
ApiClient
({
children
}:
{
children
:
React
.
ReactNode
})
{
return
<
div
className=
"api-client"
>
{
children
}
</
div
>
}
function
ConnectionHandler
({
children
}:
{
children
:
React
.
ReactNode
})
{
return
<
div
className=
"connection-handler"
>
{
children
}
</
div
>
}
async
function
ConnectionReader
()
{
await
connection
()
return
(
<
div
data
-
testid=
"connection-content"
>
...
...
@@ -40,8 +127,30 @@ async function ConnectionContent() {
)
}
function
ConnectionContent
()
{
return
(
<
ApiClient
>
<
ConnectionHandler
>
<
ConnectionReader
/>
</
ConnectionHandler
>
</
ApiClient
>
)
}
// =============================================================================
// Case 4: Static async content (for comparison)
// Case 4: Direct dynamic call (same level - optimal)
// =============================================================================
async
function
DirectHeaderContent
()
{
const
headersList
=
await
headers
()
return
(
<
div
data
-
testid=
"direct-header-content"
>
Direct header access:
{
headersList
.
get
(
'host'
)
}
</
div
>
)
}
// =============================================================================
// Case 5: Static async content (for comparison - no dynamic API)
// =============================================================================
async
function
StaticAsyncContent
()
{
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
50
))
...
...
@@ -54,23 +163,24 @@ async function StaticAsyncContent() {
export
default
function
DynamicPage
()
{
return
(
<
div
data
-
testid=
"dynamic-page-root"
>
<
h1
>
Dynamic API Test Cases
</
h1
>
<
p
>
These cases demonstrate dynamic APIs that trigger dynamic rendering.
<
div
data
-
testid=
"dynamic-page-root"
style=
{
{
padding
:
'20px'
}
}
>
<
h1
>
Dynamic API Layer Demo
</
h1
>
<
p
style=
{
{
color
:
'#666'
,
marginBottom
:
'24px'
}
}
>
Open the profiler panel to see component layers between Suspense and
dynamic API calls. Click "prompt" to copy optimization suggestions.
</
p
>
<
section
>
<
h2
>
1.
cookies() - Request cookies
</
h2
>
<
section
style=
{
{
marginBottom
:
'24px'
}
}
>
<
h2
>
1.
Deep nesting - 7 layers to cookies()
</
h2
>
<
Suspense
fallback=
{
<
div
data
-
testid=
"cookie-loading"
>
Loading cookies...
</
div
>
}
>
<
CookieContent
/>
<
Deep
CookieContent
/>
</
Suspense
>
</
section
>
<
section
>
<
h2
>
2.
headers() - Request headers
</
h2
>
<
section
style=
{
{
marginBottom
:
'24px'
}
}
>
<
h2
>
2.
Medium nesting - 3 layers to headers()
</
h2
>
<
Suspense
fallback=
{
<
div
data
-
testid=
"header-loading"
>
Loading headers...
</
div
>
}
>
...
...
@@ -78,8 +188,8 @@ export default function DynamicPage() {
</
Suspense
>
</
section
>
<
section
>
<
h2
>
3.
connection() - Explicit dynamic opt-in
</
h2
>
<
section
style=
{
{
marginBottom
:
'24px'
}
}
>
<
h2
>
3.
Medium nesting - 2 layers to connection()
</
h2
>
<
Suspense
fallback=
{
<
div
data
-
testid=
"connection-loading"
>
Loading connection...
</
div
>
...
...
@@ -89,8 +199,19 @@ export default function DynamicPage() {
</
Suspense
>
</
section
>
<
section
>
<
h2
>
4. Static async content (for comparison)
</
h2
>
<
section
style=
{
{
marginBottom
:
'24px'
}
}
>
<
h2
>
4. Direct call - headers() at same level (optimal)
</
h2
>
<
Suspense
fallback=
{
<
div
data
-
testid=
"direct-header-loading"
>
Loading direct...
</
div
>
}
>
<
DirectHeaderContent
/>
</
Suspense
>
</
section
>
<
section
style=
{
{
marginBottom
:
'24px'
}
}
>
<
h2
>
5. Static async (no dynamic API)
</
h2
>
<
Suspense
fallback=
{
<
div
data
-
testid=
"static-async-loading"
>
Loading static...
</
div
>
...
...
test/e2e/app-dir/suspense-profiling/app/layout.tsx
View file @
ae18e3db
import
Link
from
'next/link'
export
default
function
RootLayout
({
children
,
}:
{
...
...
@@ -5,7 +7,32 @@ export default function RootLayout({
})
{
return
(
<
html
>
<
body
>
{
children
}
</
body
>
<
body
>
<
nav
style=
{
{
padding
:
'12px 16px'
,
borderBottom
:
'1px solid #eee'
,
display
:
'flex'
,
gap
:
'16px'
,
fontFamily
:
'system-ui, sans-serif'
,
fontSize
:
'14px'
,
}
}
>
<
Link
href=
"/"
style=
{
{
color
:
'#0070f3'
}
}
>
Home
</
Link
>
<
Link
href=
"/dynamic"
style=
{
{
color
:
'#0070f3'
}
}
>
Dynamic APIs
</
Link
>
<
Link
href=
"/nested"
style=
{
{
color
:
'#0070f3'
}
}
>
Nested Suspense
</
Link
>
<
Link
href=
"/item/test-slug"
style=
{
{
color
:
'#0070f3'
}
}
>
Dynamic Params
</
Link
>
</
nav
>
{
children
}
</
body
>
</
html
>
)
}
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