@@ -183,6 +183,7 @@ import {
183183 createRenderResumeDataCache ,
184184} from '../resume-data-cache/resume-data-cache'
185185import type { MetadataErrorType } from '../../lib/metadata/resolve-metadata'
186+ import isError from '../../lib/is-error'
186187
187188export type GetDynamicParamFromSegment = (
188189 // [slug] / [[slug]] / [...slug]
@@ -877,6 +878,7 @@ function Preloads({ preloadCallbacks }: { preloadCallbacks: Function[] }) {
877878async function getErrorRSCPayload (
878879 tree : LoaderTree ,
879880 ctx : AppRenderContext ,
881+ ssrError : unknown ,
880882 errorType : MetadataErrorType | 'redirect' | undefined
881883) {
882884 const {
@@ -940,6 +942,11 @@ async function getErrorRSCPayload(
940942 query
941943 )
942944
945+ let err : Error | undefined = undefined
946+ if ( ssrError ) {
947+ err = isError ( ssrError ) ? ssrError : new Error ( ssrError + '' )
948+ }
949+
943950 // For metadata notFound error there's no global not found boundary on top
944951 // so we create a not found page with AppRouter
945952 const seedData : CacheNodeSeedData = [
@@ -948,7 +955,14 @@ async function getErrorRSCPayload(
948955 < head >
949956 < ErrorMetadataComponent />
950957 </ head >
951- < body />
958+ < body >
959+ { process . env . NODE_ENV !== 'production' && err ? (
960+ < template
961+ data-next-error-message = { err . message }
962+ data-next-error-stack = { err . stack }
963+ />
964+ ) : null }
965+ </ body >
952966 </ html > ,
953967 { } ,
954968 null ,
@@ -2004,6 +2018,7 @@ async function renderToStream(
20042018 getErrorRSCPayload ,
20052019 tree ,
20062020 ctx ,
2021+ reactServerErrorsByDigest . has ( ( err as any ) . digest ) ? null : err ,
20072022 errorType
20082023 )
20092024
@@ -3870,6 +3885,7 @@ async function prerenderToStream(
38703885 getErrorRSCPayload ,
38713886 tree ,
38723887 ctx ,
3888+ reactServerErrorsByDigest . has ( ( err as any ) . digest ) ? undefined : err ,
38733889 errorType
38743890 )
38753891
0 commit comments