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
88019a04
Unverified
Commit
88019a04
authored
Apr 11, 2025
by
Jiachi Liu
Committed by
GitHub
Apr 11, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add graceful error fallback for bots requests (#77916)
parent
bd628216
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
234 additions
and
28 deletions
+234
-28
app-index.tsx
packages/next/src/client/app-index.tsx
+2
-0
app-router.tsx
packages/next/src/client/components/app-router.tsx
+37
-21
app-render.tsx
packages/next/src/server/app-render/app-render.tsx
+21
-1
base-server.ts
packages/next/src/server/base-server.ts
+5
-3
render.tsx
packages/next/src/server/render.tsx
+1
-0
base.ts
test/lib/browsers/base.ts
+2
-1
playwright.ts
test/lib/browsers/playwright.ts
+4
-1
next-webdriver.ts
test/lib/next-webdriver.ts
+8
-1
async-content.tsx
...tion/app-dir/graceful-degrade-error/app/async-content.tsx
+5
-0
async-layout.tsx
...ction/app-dir/graceful-degrade-error/app/async-layout.tsx
+7
-0
content.tsx
...production/app-dir/graceful-degrade-error/app/content.tsx
+5
-0
layout-wrapper.tsx
...ion/app-dir/graceful-degrade-error/app/layout-wrapper.tsx
+7
-0
layout.tsx
.../production/app-dir/graceful-degrade-error/app/layout.tsx
+7
-0
page-client.tsx
...uction/app-dir/graceful-degrade-error/app/page-client.tsx
+12
-0
page.tsx
test/production/app-dir/graceful-degrade-error/app/page.tsx
+2
-0
delete-dynamic-chunk.js
...on/app-dir/graceful-degrade-error/delete-dynamic-chunk.js
+26
-0
graceful-degrade-error-non-bot.test.ts
...eful-degrade-error/graceful-degrade-error-non-bot.test.ts
+39
-0
graceful-degrade-error.test.ts
...dir/graceful-degrade-error/graceful-degrade-error.test.ts
+38
-0
next.config.js
.../production/app-dir/graceful-degrade-error/next.config.js
+6
-0
No files found.
packages/next/src/client/app-index.tsx
View file @
88019a04
...
...
@@ -25,6 +25,7 @@ import type { InitialRSCPayload } from '../server/app-render/types'
import
{
createInitialRouterState
}
from
'./components/router-reducer/create-initial-router-state'
import
{
MissingSlotContext
}
from
'../shared/lib/app-router-context.shared-runtime'
import
{
setAppBuildId
}
from
'./app-build-id'
import
{
isBot
}
from
'../shared/lib/router/utils/is-bot'
/// <reference types="react-dom/experimental" />
...
...
@@ -169,6 +170,7 @@ function ServerRoot({
const
router
=
(
<
AppRouter
gracefullyDegrade=
{
isBot
(
window
.
navigator
.
userAgent
)
}
actionQueue=
{
actionQueue
}
globalErrorComponentAndStyles=
{
initialRSCPayload
.
G
}
assetPrefix=
{
initialRSCPayload
.
p
}
...
...
packages/next/src/client/components/app-router.tsx
View file @
88019a04
...
...
@@ -198,10 +198,12 @@ function Router({
actionQueue
,
assetPrefix
,
globalError
,
gracefullyDegrade
,
}:
{
actionQueue
:
AppRouterActionQueue
assetPrefix
:
string
globalError
:
[
GlobalErrorComponent
,
React
.
ReactNode
]
gracefullyDegrade
:
boolean
})
{
const
state
=
useActionQueue
(
actionQueue
)
const
{
canonicalUrl
}
=
state
...
...
@@ -512,15 +514,18 @@ function Router({
</
HotReloader
>
)
}
else
{
// In production, we only apply the user-customized global error boundary.
content
=
(
<
ErrorBoundary
errorComponent=
{
globalError
[
0
]
}
errorStyles=
{
globalError
[
1
]
}
>
{
content
}
</
ErrorBoundary
>
)
// If gracefully degrading is applied in production,
// leave the app as it is rather than caught by GlobalError boundary.
if
(
!
gracefullyDegrade
)
{
content
=
(
<
ErrorBoundary
errorComponent=
{
globalError
[
0
]
}
errorStyles=
{
globalError
[
1
]
}
>
{
content
}
</
ErrorBoundary
>
)
}
}
return
(
...
...
@@ -555,26 +560,37 @@ export default function AppRouter({
actionQueue
,
globalErrorComponentAndStyles
:
[
globalErrorComponent
,
globalErrorStyles
],
assetPrefix
,
gracefullyDegrade
,
}:
{
actionQueue
:
AppRouterActionQueue
globalErrorComponentAndStyles
:
[
GlobalErrorComponent
,
React
.
ReactNode
]
assetPrefix
:
string
gracefullyDegrade
:
boolean
})
{
useNavFailureHandler
()
return
(
<
ErrorBoundary
// At the very top level, use the default GlobalError component as the final fallback.
// When the app router itself fails, which means the framework itself fails, we show the default error.
errorComponent=
{
DefaultGlobalError
}
>
<
Router
actionQueue=
{
actionQueue
}
assetPrefix=
{
assetPrefix
}
globalError=
{
[
globalErrorComponent
,
globalErrorStyles
]
}
/>
</
ErrorBoundary
>
const
router
=
(
<
Router
actionQueue=
{
actionQueue
}
assetPrefix=
{
assetPrefix
}
globalError=
{
[
globalErrorComponent
,
globalErrorStyles
]
}
gracefullyDegrade=
{
gracefullyDegrade
}
/>
)
if
(
gracefullyDegrade
)
{
return
router
}
else
{
return
(
<
ErrorBoundary
// At the very top level, use the default GlobalError component as the final fallback.
// When the app router itself fails, which means the framework itself fails, we show the default error.
errorComponent=
{
DefaultGlobalError
}
>
{
router
}
</
ErrorBoundary
>
)
}
}
const
runtimeStyles
=
new
Set
<
string
>
()
...
...
packages/next/src/server/app-render/app-render.tsx
View file @
88019a04
...
...
@@ -1075,15 +1075,17 @@ function App<T>({
reactServerStream
,
preinitScripts
,
clientReferenceManifest
,
nonce
,
ServerInsertedHTMLProvider
,
ServerInsertedMetadataProvider
,
gracefullyDegrade
,
nonce
,
}:
{
reactServerStream
:
BinaryStreamOf
<
T
>
preinitScripts
:
()
=>
void
clientReferenceManifest
:
NonNullable
<
RenderOpts
[
'clientReferenceManifest'
]
>
ServerInsertedHTMLProvider
:
React
.
ComponentType
<
{
children
:
JSX
.
Element
}
>
ServerInsertedMetadataProvider
:
React
.
ComponentType
<
{
children
:
JSX
.
Element
}
>
gracefullyDegrade
:
boolean
nonce
?:
string
}):
JSX
.
Element
{
preinitScripts
()
...
...
@@ -1128,6 +1130,7 @@ function App<T>({
actionQueue=
{
actionQueue
}
globalErrorComponentAndStyles=
{
response
.
G
}
assetPrefix=
{
response
.
p
}
gracefullyDegrade=
{
gracefullyDegrade
}
/>
</
ServerInsertedHTMLProvider
>
</
ServerInsertedMetadataProvider
>
...
...
@@ -1144,6 +1147,7 @@ function ErrorApp<T>({
clientReferenceManifest
,
ServerInsertedMetadataProvider
,
ServerInsertedHTMLProvider
,
gracefullyDegrade
,
nonce
,
}:
{
reactServerStream
:
BinaryStreamOf
<
T
>
...
...
@@ -1151,6 +1155,7 @@ function ErrorApp<T>({
clientReferenceManifest
:
NonNullable
<
RenderOpts
[
'clientReferenceManifest'
]
>
ServerInsertedMetadataProvider
:
React
.
ComponentType
<
{
children
:
JSX
.
Element
}
>
ServerInsertedHTMLProvider
:
React
.
ComponentType
<
{
children
:
JSX
.
Element
}
>
gracefullyDegrade
:
boolean
nonce
?:
string
}):
JSX
.
Element
{
preinitScripts
()
...
...
@@ -1186,6 +1191,7 @@ function ErrorApp<T>({
actionQueue=
{
actionQueue
}
globalErrorComponentAndStyles=
{
response
.
G
}
assetPrefix=
{
response
.
p
}
gracefullyDegrade=
{
gracefullyDegrade
}
/>
</
ServerInsertedHTMLProvider
>
</
ServerInsertedMetadataProvider
>
...
...
@@ -1960,6 +1966,7 @@ async function renderToStream(
ServerInsertedHTMLProvider=
{
ServerInsertedHTMLProvider
}
ServerInsertedMetadataProvider=
{
ServerInsertedMetadataProvider
}
nonce=
{
ctx
.
nonce
}
gracefullyDegrade=
{
!!
ctx
.
renderOpts
.
botType
}
/>,
postponed
,
{
...
...
@@ -2000,6 +2007,7 @@ async function renderToStream(
clientReferenceManifest=
{
clientReferenceManifest
}
ServerInsertedHTMLProvider=
{
ServerInsertedHTMLProvider
}
ServerInsertedMetadataProvider=
{
ServerInsertedMetadataProvider
}
gracefullyDegrade=
{
!!
ctx
.
renderOpts
.
botType
}
nonce=
{
ctx
.
nonce
}
/>,
{
...
...
@@ -2157,6 +2165,7 @@ async function renderToStream(
ServerInsertedHTMLProvider=
{
ServerInsertedHTMLProvider
}
preinitScripts=
{
errorPreinitScripts
}
clientReferenceManifest=
{
clientReferenceManifest
}
gracefullyDegrade=
{
!!
ctx
.
renderOpts
.
botType
}
nonce=
{
ctx
.
nonce
}
/>
),
...
...
@@ -2378,6 +2387,7 @@ async function spawnDynamicValidationInDev(
clientReferenceManifest=
{
clientReferenceManifest
}
ServerInsertedHTMLProvider=
{
ServerInsertedHTMLProvider
}
ServerInsertedMetadataProvider=
{
ServerInsertedMetadataProvider
}
gracefullyDegrade=
{
!!
ctx
.
renderOpts
.
botType
}
nonce=
{
nonce
}
/>,
{
...
...
@@ -2523,6 +2533,7 @@ async function spawnDynamicValidationInDev(
clientReferenceManifest=
{
clientReferenceManifest
}
ServerInsertedHTMLProvider=
{
ServerInsertedHTMLProvider
}
ServerInsertedMetadataProvider=
{
ServerInsertedMetadataProvider
}
gracefullyDegrade=
{
!!
ctx
.
renderOpts
.
botType
}
nonce=
{
ctx
.
nonce
}
/>,
{
...
...
@@ -2912,6 +2923,7 @@ async function prerenderToStream(
ServerInsertedMetadataProvider=
{
ServerInsertedMetadataProvider
}
gracefullyDegrade=
{
!!
ctx
.
renderOpts
.
botType
}
nonce=
{
nonce
}
/>,
{
...
...
@@ -3070,6 +3082,7 @@ async function prerenderToStream(
clientReferenceManifest=
{
clientReferenceManifest
}
ServerInsertedHTMLProvider=
{
ServerInsertedHTMLProvider
}
ServerInsertedMetadataProvider=
{
ServerInsertedMetadataProvider
}
gracefullyDegrade=
{
!!
ctx
.
renderOpts
.
botType
}
nonce=
{
nonce
}
/>,
{
...
...
@@ -3195,6 +3208,7 @@ async function prerenderToStream(
clientReferenceManifest=
{
clientReferenceManifest
}
ServerInsertedHTMLProvider=
{
ServerInsertedHTMLProvider
}
ServerInsertedMetadataProvider=
{
ServerInsertedMetadataProvider
}
gracefullyDegrade=
{
!!
ctx
.
renderOpts
.
botType
}
nonce=
{
nonce
}
/>,
JSON
.
parse
(
JSON
.
stringify
(
postponed
)),
...
...
@@ -3386,6 +3400,7 @@ async function prerenderToStream(
clientReferenceManifest=
{
clientReferenceManifest
}
ServerInsertedHTMLProvider=
{
ServerInsertedHTMLProvider
}
ServerInsertedMetadataProvider=
{
ServerInsertedMetadataProvider
}
gracefullyDegrade=
{
!!
ctx
.
renderOpts
.
botType
}
nonce=
{
nonce
}
/>,
{
...
...
@@ -3541,6 +3556,7 @@ async function prerenderToStream(
ServerInsertedMetadataProvider=
{
ServerInsertedMetadataProvider
}
gracefullyDegrade=
{
!!
ctx
.
renderOpts
.
botType
}
nonce=
{
nonce
}
/>,
{
...
...
@@ -3720,6 +3736,7 @@ async function prerenderToStream(
clientReferenceManifest=
{
clientReferenceManifest
}
ServerInsertedHTMLProvider=
{
ServerInsertedHTMLProvider
}
ServerInsertedMetadataProvider=
{
ServerInsertedMetadataProvider
}
gracefullyDegrade=
{
!!
ctx
.
renderOpts
.
botType
}
nonce=
{
nonce
}
/>,
{
...
...
@@ -3852,6 +3869,7 @@ async function prerenderToStream(
clientReferenceManifest=
{
clientReferenceManifest
}
ServerInsertedHTMLProvider=
{
ServerInsertedHTMLProvider
}
ServerInsertedMetadataProvider=
{
ServerInsertedMetadataProvider
}
gracefullyDegrade=
{
!!
ctx
.
renderOpts
.
botType
}
nonce=
{
nonce
}
/>,
JSON
.
parse
(
JSON
.
stringify
(
postponed
)),
...
...
@@ -3931,6 +3949,7 @@ async function prerenderToStream(
clientReferenceManifest=
{
clientReferenceManifest
}
ServerInsertedHTMLProvider=
{
ServerInsertedHTMLProvider
}
ServerInsertedMetadataProvider=
{
ServerInsertedMetadataProvider
}
gracefullyDegrade=
{
!!
ctx
.
renderOpts
.
botType
}
nonce=
{
nonce
}
/>,
{
...
...
@@ -4095,6 +4114,7 @@ async function prerenderToStream(
ServerInsertedHTMLProvider=
{
ServerInsertedHTMLProvider
}
preinitScripts=
{
errorPreinitScripts
}
clientReferenceManifest=
{
clientReferenceManifest
}
gracefullyDegrade=
{
!!
ctx
.
renderOpts
.
botType
}
nonce=
{
nonce
}
/>
),
...
...
packages/next/src/server/base-server.ts
View file @
88019a04
...
...
@@ -1795,14 +1795,13 @@ export default abstract class Server<
>
):
Promise
<
void
>
{
const
ua
=
partialContext
.
req
.
headers
[
'user-agent'
]
||
''
const
isBotRequest
=
isBot
(
ua
)
const
ctx
:
RequestContext
<
ServerRequest
,
ServerResponse
>
=
{
...
partialContext
,
renderOpts
:
{
...
this
.
renderOpts
,
supportsDynamicResponse
:
!
isBotRequest
,
botType
:
getBotType
(
ua
)
,
// `renderOpts.botType` is accumulated in `this.renderImpl()`
supportsDynamicResponse
:
!
this
.
renderOpts
.
botType
,
serveStreamingMetadata
:
shouldServeStreamingMetadata
(
ua
,
this
.
nextConfig
.
htmlLimitedBots
...
...
@@ -1933,6 +1932,9 @@ export default abstract class Server<
pathname
=
'/'
}
const
ua
=
req
.
headers
[
'user-agent'
]
||
''
this
.
renderOpts
.
botType
=
getBotType
(
ua
)
// we allow custom servers to call render for all URLs
// so check if we need to serve a static _next file or not.
// we don't modify the URL for _next/data request but still
...
...
packages/next/src/server/render.tsx
View file @
88019a04
...
...
@@ -283,6 +283,7 @@ export type RenderOptsPartial = {
isPossibleServerAction
?:
boolean
isExperimentalCompile
?:
boolean
isPrefetch
?:
boolean
isBot
?:
boolean
expireTime
?:
number
experimental
:
{
clientTraceMetadata
?:
string
[]
...
...
test/lib/browsers/base.ts
View file @
88019a04
...
...
@@ -54,7 +54,8 @@ export abstract class BrowserInterface<TCurrent = any> {
locale
:
string
,
javaScriptEnabled
:
boolean
,
ignoreHttpsErrors
:
boolean
,
headless
:
boolean
headless
:
boolean
,
userAgent
:
string
|
undefined
):
Promise
<
void
>
abstract
close
():
Promise
<
void
>
...
...
test/lib/browsers/playwright.ts
View file @
88019a04
...
...
@@ -125,7 +125,8 @@ export class Playwright extends BrowserInterface {
locale
:
string
,
javaScriptEnabled
:
boolean
,
ignoreHTTPSErrors
:
boolean
,
headless
:
boolean
headless
:
boolean
,
userAgent
:
string
|
undefined
)
{
let
device
...
...
@@ -148,6 +149,7 @@ export class Playwright extends BrowserInterface {
locale
,
javaScriptEnabled
,
ignoreHTTPSErrors
,
...(
userAgent
?
{
userAgent
}
:
{}),
...
device
,
})
contextHasJSEnabled
=
javaScriptEnabled
...
...
@@ -160,6 +162,7 @@ export class Playwright extends BrowserInterface {
locale
,
javaScriptEnabled
,
ignoreHTTPSErrors
,
...(
userAgent
?
{
userAgent
}
:
{}),
...
device
,
})
contextHasJSEnabled
=
javaScriptEnabled
...
...
test/lib/next-webdriver.ts
View file @
88019a04
...
...
@@ -75,6 +75,11 @@ export interface WebdriverOptions {
ignoreHTTPSErrors
?:
boolean
cpuThrottleRate
?:
number
pushErrorAsConsoleLog
?:
boolean
/**
* Override the user agent
*/
userAgent
?:
string
}
/**
...
...
@@ -107,6 +112,7 @@ export default async function webdriver(
headless
,
cpuThrottleRate
,
pushErrorAsConsoleLog
,
userAgent
,
}
=
options
const
{
Playwright
,
quit
}
=
await
import
(
'./browsers/playwright'
)
...
...
@@ -121,7 +127,8 @@ export default async function webdriver(
!
disableJavaScript
,
ignoreHTTPSErrors
,
// allow headless to be overwritten for a particular test
typeof
headless
!==
'undefined'
?
headless
:
!!
process
.
env
.
HEADLESS
typeof
headless
!==
'undefined'
?
headless
:
!!
process
.
env
.
HEADLESS
,
userAgent
)
;(
global
as
any
).
browserName
=
browserName
...
...
test/production/app-dir/graceful-degrade-error/app/async-content.tsx
0 → 100644
View file @
88019a04
'use client'
import
dynamic
from
'next/dynamic'
export
const
Large
=
dynamic
(()
=>
import
(
'./content'
))
test/production/app-dir/graceful-degrade-error/app/async-layout.tsx
0 → 100644
View file @
88019a04
'use client'
import
dynamic
from
'next/dynamic'
const
AsyncLayout
=
dynamic
(
async
()
=>
import
(
'./layout-wrapper'
))
export
default
AsyncLayout
test/production/app-dir/graceful-degrade-error/app/content.tsx
0 → 100644
View file @
88019a04
'use client'
export
default
function
Large
()
{
return
<
p
>
large test content
</
p
>
}
test/production/app-dir/graceful-degrade-error/app/layout-wrapper.tsx
0 → 100644
View file @
88019a04
'use client'
export
default
({
children
}:
any
)
=>
(
<
html
className=
"layout-cls"
>
<
body
className=
"body-cls"
>
{
children
}
</
body
>
</
html
>
)
test/production/app-dir/graceful-degrade-error/app/layout.tsx
0 → 100644
View file @
88019a04
'use client'
import
AsyncLayout
from
'./async-layout'
export
default
function
Root
({
children
}:
{
children
:
React
.
ReactNode
})
{
return
<
AsyncLayout
>
{
children
}
</
AsyncLayout
>
}
test/production/app-dir/graceful-degrade-error/app/page-client.tsx
0 → 100644
View file @
88019a04
'use client'
import
{
Large
}
from
'./async-content'
export
default
function
Page
()
{
return
(
<
div
className=
"page"
>
<
p
>
hello world von server
</
p
>
<
Large
/>
</
div
>
)
}
test/production/app-dir/graceful-degrade-error/app/page.tsx
0 → 100644
View file @
88019a04
export
{
default
}
from
'./page-client'
export
const
dynamic
=
'force-dynamic'
test/production/app-dir/graceful-degrade-error/delete-dynamic-chunk.js
0 → 100644
View file @
88019a04
import
fs
from
'fs'
import
path
from
'path'
export
function
deleteBrowserDynamicChunks
(
next
)
{
const
clientChunkDir
=
path
.
join
(
next
.
testDir
,
'.next'
,
'static'
,
'chunks'
)
const
clientChunkFiles
=
fs
.
readdirSync
(
clientChunkDir
)
// filter out the js file that contains the text "large test content"
.
filter
((
filename
)
=>
{
const
filePath
=
path
.
join
(
clientChunkDir
,
filename
)
const
isJsFile
=
filename
.
endsWith
(
'.js'
)
const
fileContent
=
isJsFile
?
fs
.
readFileSync
(
filePath
,
{
encoding
:
'utf8'
})
:
''
return
(
isJsFile
&&
fileContent
&&
fileContent
.
includes
(
'large test content'
)
)
})
.
map
((
file
)
=>
path
.
join
(
clientChunkDir
,
file
))
// Intended to log to help debugging tests
console
.
log
(
'Deleting client chunk files:'
,
clientChunkFiles
)
// delete all chunk files
clientChunkFiles
.
map
((
file
)
=>
fs
.
rmSync
(
file
))
}
test/production/app-dir/graceful-degrade-error/graceful-degrade-error-non-bot.test.ts
0 → 100644
View file @
88019a04
// Duplicate the test file of graceful-degrade-error-bot.test.ts since we need to
// restart with a new browser context for UA setting. Otherwise the browser context
// will not be closed and reset properly. TODO: investigate why browser.close didn't help.
import
{
nextTestSetup
}
from
'e2e-utils'
import
{
deleteBrowserDynamicChunks
}
from
'./delete-dynamic-chunk'
describe
(
'graceful-degrade-error - non bot'
,
()
=>
{
const
{
next
}
=
nextTestSetup
({
files
:
__dirname
,
})
// Delete client chunks to simulate chunk loading failure
beforeAll
(()
=>
{
deleteBrowserDynamicChunks
(
next
)
})
it
(
'should not degrade to graceful error when chunk loading fails in ssr for non-bot user agents'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/'
)
const
logs
=
await
browser
.
log
()
const
errors
=
logs
.
filter
((
x
)
=>
x
.
source
===
'error'
)
.
map
((
x
)
=>
x
.
message
)
.
join
(
'
\
n'
)
expect
(
errors
).
toMatch
(
/Failed to load resource./
)
// Should not show the original content
const
html
=
await
browser
.
elementByCss
(
'html'
)
const
body
=
await
browser
.
elementByCss
(
'body'
)
expect
(
await
html
.
getAttribute
(
'class'
)).
not
.
toBe
(
'layout-cls'
)
expect
(
await
body
.
getAttribute
(
'class'
)).
not
.
toBe
(
'body-cls'
)
const
bodyText
=
await
body
.
text
()
expect
(
bodyText
).
toMatch
(
/Application error: a client-side exception has occurred while loading/
)
})
})
test/production/app-dir/graceful-degrade-error/graceful-degrade-error.test.ts
0 → 100644
View file @
88019a04
import
{
nextTestSetup
}
from
'e2e-utils'
import
{
deleteBrowserDynamicChunks
}
from
'./delete-dynamic-chunk'
describe
(
'graceful-degrade-error'
,
()
=>
{
const
{
next
}
=
nextTestSetup
({
files
:
__dirname
,
})
// Delete client chunks to simulate chunk loading failure
beforeAll
(()
=>
{
deleteBrowserDynamicChunks
(
next
)
})
it
(
'should degrade to graceful error when chunk loading fails in ssr for bot'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/'
,
{
userAgent
:
'Googlebot'
,
})
const
logs
=
await
browser
.
log
()
const
errors
=
logs
.
filter
((
x
)
=>
x
.
source
===
'error'
)
.
map
((
x
)
=>
x
.
message
)
.
join
(
'
\
n'
)
expect
(
errors
).
toMatch
(
/Failed to load resource./
)
// Should show the original content
const
originHtml
=
await
browser
.
elementByCss
(
'html'
)
const
originBody
=
await
browser
.
elementByCss
(
'body'
)
expect
(
await
originHtml
.
getAttribute
(
'class'
)).
toBe
(
'layout-cls'
)
expect
(
await
originBody
.
getAttribute
(
'class'
)).
toBe
(
'body-cls'
)
// Do not contain the global error boundary text
const
bodyText
=
await
originBody
.
text
()
expect
(
bodyText
).
not
.
toMatch
(
/Application error: a client-side exception has occurred while loading/
)
})
})
test/production/app-dir/graceful-degrade-error/next.config.js
0 → 100644
View file @
88019a04
/**
* @type {import('next').NextConfig}
*/
const
nextConfig
=
{}
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