Skip to content

Commit a20108a

Browse files
committed
Only warn on large Shell errors
1 parent 88e78fa commit a20108a

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
@@ -193,6 +193,7 @@ import {
193193
trackPendingModules,
194194
} from './module-loading/track-module-loading.external'
195195
import { isUseCacheTimeoutError } from '../use-cache/use-cache-errors'
196+
import { isReactLargeShellError } from './react-large-shell-error'
196197

197198
export type GetDynamicParamFromSegment = (
198199
// [slug] / [[slug]] / [...slug]
@@ -2336,6 +2337,12 @@ async function spawnDynamicValidationInDev(
23362337
return digest
23372338
}
23382339

2340+
if (isReactLargeShellError(err)) {
2341+
// TODO: Aggregate
2342+
console.error(err)
2343+
return undefined
2344+
}
2345+
23392346
if (initialServerPrerenderController.signal.aborted) {
23402347
// The render aborted before this error was handled which indicates
23412348
// the error is caused by unfinished components within the render
@@ -2442,6 +2449,12 @@ async function spawnDynamicValidationInDev(
24422449
return digest
24432450
}
24442451

2452+
if (isReactLargeShellError(err)) {
2453+
// TODO: Aggregate
2454+
console.error(err)
2455+
return undefined
2456+
}
2457+
24452458
if (initialClientController.signal.aborted) {
24462459
// These are expected errors that might error the prerender. we ignore them.
24472460
} else if (
@@ -2531,6 +2544,12 @@ async function spawnDynamicValidationInDev(
25312544
return err.digest
25322545
}
25332546

2547+
if (isReactLargeShellError(err)) {
2548+
// TODO: Aggregate
2549+
console.error(err)
2550+
return undefined
2551+
}
2552+
25342553
return getDigestForWellKnownError(err)
25352554
},
25362555
signal: finalServerController.signal,
@@ -2605,6 +2624,12 @@ async function spawnDynamicValidationInDev(
26052624
return
26062625
}
26072626

2627+
if (isReactLargeShellError(err)) {
2628+
// TODO: Aggregate
2629+
console.error(err)
2630+
return undefined
2631+
}
2632+
26082633
return getDigestForWellKnownError(err)
26092634
},
26102635
// We don't need bootstrap scripts in this prerender
@@ -2915,6 +2940,12 @@ async function prerenderToStream(
29152940
return digest
29162941
}
29172942

2943+
if (isReactLargeShellError(err)) {
2944+
// TODO: Aggregate
2945+
console.error(err)
2946+
return undefined
2947+
}
2948+
29182949
if (initialServerPrerenderController.signal.aborted) {
29192950
// The render aborted before this error was handled which indicates
29202951
// the error is caused by unfinished components within the render
@@ -3037,6 +3068,12 @@ async function prerenderToStream(
30373068
return digest
30383069
}
30393070

3071+
if (isReactLargeShellError(err)) {
3072+
// TODO: Aggregate
3073+
console.error(err)
3074+
return undefined
3075+
}
3076+
30403077
if (initialClientController.signal.aborted) {
30413078
// These are expected errors that might error the prerender. we ignore them.
30423079
} 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)