Skip to content

Commit e969e64

Browse files
committed
Downgrade large shell error to warning
1 parent b520e32 commit e969e64

File tree

5 files changed

+83
-0
lines changed

5 files changed

+83
-0
lines changed

packages/next/src/server/app-render/app-render.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ import {
198198
trackPendingImport,
199199
trackPendingModules,
200200
} from './module-loading/track-module-loading.external'
201+
import { isReactLargeShellError } from './react-large-shell-error'
201202
import type { GlobalErrorComponent } from '../../client/components/global-error'
202203

203204
export type GetDynamicParamFromSegment = (
@@ -2358,6 +2359,12 @@ async function spawnDynamicValidationInDev(
23582359
return digest
23592360
}
23602361

2362+
if (isReactLargeShellError(err)) {
2363+
// TODO: Aggregate
2364+
console.error(err)
2365+
return undefined
2366+
}
2367+
23612368
if (initialServerPrerenderController.signal.aborted) {
23622369
// The render aborted before this error was handled which indicates
23632370
// the error is caused by unfinished components within the render
@@ -2466,6 +2473,12 @@ async function spawnDynamicValidationInDev(
24662473
return digest
24672474
}
24682475

2476+
if (isReactLargeShellError(err)) {
2477+
// TODO: Aggregate
2478+
console.error(err)
2479+
return undefined
2480+
}
2481+
24692482
if (initialClientController.signal.aborted) {
24702483
// These are expected errors that might error the prerender. we ignore them.
24712484
} else if (
@@ -2557,6 +2570,12 @@ async function spawnDynamicValidationInDev(
25572570
return err.digest
25582571
}
25592572

2573+
if (isReactLargeShellError(err)) {
2574+
// TODO: Aggregate
2575+
console.error(err)
2576+
return undefined
2577+
}
2578+
25602579
return getDigestForWellKnownError(err)
25612580
},
25622581
signal: finalServerController.signal,
@@ -2633,6 +2652,12 @@ async function spawnDynamicValidationInDev(
26332652
return
26342653
}
26352654

2655+
if (isReactLargeShellError(err)) {
2656+
// TODO: Aggregate
2657+
console.error(err)
2658+
return undefined
2659+
}
2660+
26362661
return getDigestForWellKnownError(err)
26372662
},
26382663
// We don't need bootstrap scripts in this prerender
@@ -2957,6 +2982,12 @@ async function prerenderToStream(
29572982
return digest
29582983
}
29592984

2985+
if (isReactLargeShellError(err)) {
2986+
// TODO: Aggregate
2987+
console.error(err)
2988+
return undefined
2989+
}
2990+
29602991
if (initialServerPrerenderController.signal.aborted) {
29612992
// The render aborted before this error was handled which indicates
29622993
// the error is caused by unfinished components within the render
@@ -3058,6 +3089,12 @@ async function prerenderToStream(
30583089
return digest
30593090
}
30603091

3092+
if (isReactLargeShellError(err)) {
3093+
// TODO: Aggregate
3094+
console.error(err)
3095+
return undefined
3096+
}
3097+
30613098
if (initialClientController.signal.aborted) {
30623099
// These are expected errors that might error the prerender. we ignore them.
30633100
} else if (

packages/next/src/server/app-render/create-error-handler.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { isDynamicServerError } from '../../client/components/hooks-server-conte
99
import { isNextRouterError } from '../../client/components/is-next-router-error'
1010
import { getProperError } from '../../lib/is-error'
1111
import { createDigestWithErrorCode } from '../../lib/error-telemetry-utils'
12+
import { isReactLargeShellError } from './react-large-shell-error'
1213

1314
declare global {
1415
var __next_log_error__: undefined | ((err: unknown) => void)
@@ -62,6 +63,12 @@ export function createFlightReactServerErrorHandler(
6263
return digest
6364
}
6465

66+
if (isReactLargeShellError(thrownValue)) {
67+
// TODO: Aggregate
68+
console.error(thrownValue)
69+
return undefined
70+
}
71+
6572
const err = getProperError(thrownValue) as DigestedError
6673

6774
// If the error already has a digest, respect the original digest,
@@ -114,6 +121,12 @@ export function createHTMLReactServerErrorHandler(
114121
return digest
115122
}
116123

124+
if (isReactLargeShellError(thrownValue)) {
125+
// TODO: Aggregate
126+
console.error(thrownValue)
127+
return undefined
128+
}
129+
117130
const err = getProperError(thrownValue) as DigestedError
118131

119132
// If the error already has a digest, respect the original digest,
@@ -171,6 +184,12 @@ export function createHTMLErrorHandler(
171184
onHTMLRenderSSRError: (err: DigestedError, errorInfo?: ErrorInfo) => void
172185
): SSRErrorHandler {
173186
return (thrownValue: unknown, errorInfo?: ErrorInfo) => {
187+
if (isReactLargeShellError(thrownValue)) {
188+
// TODO: Aggregate
189+
console.error(thrownValue)
190+
return undefined
191+
}
192+
174193
let isSSRError = true
175194

176195
allCapturedErrors.push(thrownValue)

packages/next/src/server/app-render/prospective-render-utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getDigestForWellKnownError } from './create-error-handler'
2+
import { isReactLargeShellError } from './react-large-shell-error'
23

34
export function printDebugThrownValueForProspectiveRender(
45
thrownValue: unknown,
@@ -9,6 +10,12 @@ export function printDebugThrownValueForProspectiveRender(
910
return
1011
}
1112

13+
if (isReactLargeShellError(thrownValue)) {
14+
// TODO: Aggregate
15+
console.error(thrownValue)
16+
return undefined
17+
}
18+
1219
let message: undefined | string
1320
if (
1421
typeof thrownValue === 'object' &&
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// TODO: isWellKnownError -> isNextInternalError
2+
// isReactLargeShellError -> isWarning
3+
export function isReactLargeShellError(
4+
error: unknown
5+
): error is Error & { digest?: string } {
6+
return (
7+
typeof error === 'object' &&
8+
error !== null &&
9+
'message' in error &&
10+
typeof error.message === 'string' &&
11+
error.message.startsWith('This rendered a large document (>')
12+
)
13+
}

packages/next/src/server/use-cache/use-cache-wrapper.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import type { Params } from '../request/params'
5353
import React from 'react'
5454
import { createLazyResult, isResolvedLazyResult } from '../lib/lazy-result'
5555
import { dynamicAccessAsyncStorage } from '../app-render/dynamic-access-async-storage.external'
56+
import { isReactLargeShellError } from '../app-render/react-large-shell-error'
5657

5758
type CacheKeyParts =
5859
| [buildId: string, id: string, args: unknown[]]
@@ -400,6 +401,12 @@ async function generateCacheEntryImpl(
400401
return digest
401402
}
402403

404+
if (isReactLargeShellError(error)) {
405+
// TODO: Aggregate
406+
console.error(error)
407+
return undefined
408+
}
409+
403410
if (process.env.NODE_ENV !== 'development') {
404411
// TODO: For now we're also reporting the error here, because in
405412
// production, the "Server" environment will only get the obfuscated

0 commit comments

Comments
 (0)