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
8b91c433
Commit
8b91c433
authored
Aug 07, 2025
by
Jude Gao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not force BLOCKING_STATIC_RENDER for DOM bots
parent
0dc264a4
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
100 additions
and
1 deletion
+100
-1
app-page.ts
packages/next/src/build/templates/app-page.ts
+9
-1
page.tsx
test/e2e/app-dir/cache-components-bot-ua/app/[slug]/page.tsx
+29
-0
layout.tsx
test/e2e/app-dir/cache-components-bot-ua/app/layout.tsx
+22
-0
cache-components-bot-ua.test.ts
...r/cache-components-bot-ua/cache-components-bot-ua.test.ts
+32
-0
next.config.js
test/e2e/app-dir/cache-components-bot-ua/next.config.js
+8
-0
No files found.
packages/next/src/build/templates/app-page.ts
View file @
8b91c433
...
@@ -656,8 +656,16 @@ export async function handler(
...
@@ -656,8 +656,16 @@ export async function handler(
// When serving a bot request, we want to serve a blocking render and not
// When serving a bot request, we want to serve a blocking render and not
// the prerendered page. This ensures that the correct content is served
// the prerendered page. This ensures that the correct content is served
// to the bot in the head.
// to the bot in the head.
// Skip this fallback mode change for DOM bots with PPR to allow them to use
// the same fallback cache mechanism as regular users. HTML bots should always
// use BLOCKING_STATIC_RENDER to ensure correct content is served.
if
(
fallbackMode
===
FallbackMode
.
PRERENDER
&&
isBot
(
userAgent
))
{
if
(
fallbackMode
===
FallbackMode
.
PRERENDER
&&
isBot
(
userAgent
))
{
fallbackMode
=
FallbackMode
.
BLOCKING_STATIC_RENDER
// For DOM bots with PPR, keep PRERENDER mode to allow fallback cache lookup
if
(
isRoutePPREnabled
&&
botType
===
'dom'
)
{
// Keep PRERENDER mode
}
else
{
fallbackMode
=
FallbackMode
.
BLOCKING_STATIC_RENDER
}
}
}
if
(
previousCacheEntry
?.
isStale
===
-
1
)
{
if
(
previousCacheEntry
?.
isStale
===
-
1
)
{
...
...
test/e2e/app-dir/cache-components-bot-ua/app/[slug]/page.tsx
0 → 100644
View file @
8b91c433
import
React
from
'react'
import
type
{
Metadata
}
from
'next'
export
async
function
generateMetadata
():
Promise
<
Metadata
>
{
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
1000
))
// Simulate a delay
return
{
title
:
'Home'
,
description
:
'Welcome to the home page'
,
}
}
export
default
async
function
Home
({
params
,
}:
{
params
:
Promise
<
{
slug
:
string
}
>
})
{
const
{
slug
}
=
await
params
// Math.random() will cause SSG_BAILOUT if static generation runs
// Bots should bypass static generation in PPR to avoid this error
const
randomValue
=
Math
.
random
()
return
(
<>
<
h1
>
{
slug
}
</
h1
>
<
p
>
{
randomValue
}
</
p
>
</>
)
}
test/e2e/app-dir/cache-components-bot-ua/app/layout.tsx
0 → 100644
View file @
8b91c433
import
React
,
{
Suspense
}
from
'react'
import
type
{
Metadata
}
from
'next'
export
const
metadata
:
Metadata
=
{
title
:
'PPR Bot SSG Bypass Test'
,
description
:
'Test bot static generation bypass with PPR and cache components'
,
}
export
default
function
RootLayout
({
children
,
}:
{
children
:
React
.
ReactNode
})
{
return
(
<
html
lang=
"en"
>
<
body
>
<
Suspense
>
{
children
}
</
Suspense
>
</
body
>
</
html
>
)
}
test/e2e/app-dir/cache-components-bot-ua/cache-components-bot-ua.test.ts
0 → 100644
View file @
8b91c433
import
{
nextTestSetup
}
from
'e2e-utils'
describe
(
'cache-components PPR bot static generation bypass'
,
()
=>
{
const
{
next
}
=
nextTestSetup
({
files
:
__dirname
,
})
it
(
'should bypass static generation for DOM bot requests to avoid SSG_BAILOUT'
,
async
()
=>
{
const
res
=
await
next
.
fetch
(
'/foo'
,
{
headers
:
{
'user-agent'
:
'Googlebot'
,
},
})
// With cache components + PPR enabled, DOM bots should behave like regular users
// and use the fallback cache mechanism. This allows them to handle dynamic content
// like Math.random() without triggering SSG_BAILOUT errors.
expect
(
res
.
status
).
toBe
(
200
)
// Verify that the response contains the page content
const
html
=
await
res
.
text
()
// Check that the page rendered successfully
// With PPR, content is streamed via script tags
expect
(
html
).
toContain
(
'
\\
"children
\\
":
\\
"foo
\\
"'
)
// Verify Math.random() was executed (check for a decimal number in the streamed content)
expect
(
html
).
toMatch
(
/
\\
"children
\\
":0
\.\d
+/
)
// With PPR, content is streamed, but the important thing is that
// the page rendered without a 500 error
})
})
test/e2e/app-dir/cache-components-bot-ua/next.config.js
0 → 100644
View file @
8b91c433
/** @type {import('next').NextConfig} */
const
nextConfig
=
{
experimental
:
{
cacheComponents
:
true
,
},
}
module
.
exports
=
nextConfig
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