@@ -796,11 +796,11 @@ export type InstantValidationState = {
796796 dynamicErrors : Array < Error >
797797 validationPreventingErrors : Array < Error >
798798 thrownErrorsOutsideBoundary : Array < unknown >
799- debugInstantStack : Error | null
799+ createInstantStack : ( ( ) => Error ) | null
800800}
801801
802802export function createInstantValidationState (
803- debugInstantStack : Error | null
803+ createInstantStack : ( ( ) => Error ) | null
804804) : InstantValidationState {
805805 return {
806806 hasDynamicMetadata : false ,
@@ -811,7 +811,7 @@ export function createInstantValidationState(
811811 dynamicErrors : [ ] ,
812812 validationPreventingErrors : [ ] ,
813813 thrownErrorsOutsideBoundary : [ ] ,
814- debugInstantStack ,
814+ createInstantStack ,
815815 }
816816}
817817
@@ -836,7 +836,7 @@ export function trackDynamicHoleInNavigation(
836836 const error = createErrorWithComponentOrOwnerStack (
837837 message ,
838838 componentStack ,
839- dynamicValidation . debugInstantStack
839+ dynamicValidation . createInstantStack
840840 )
841841 dynamicValidation . dynamicMetadata = error
842842 return
@@ -850,7 +850,7 @@ export function trackDynamicHoleInNavigation(
850850 const error = createErrorWithComponentOrOwnerStack (
851851 message ,
852852 componentStack ,
853- dynamicValidation . debugInstantStack
853+ dynamicValidation . createInstantStack
854854 )
855855 dynamicValidation . dynamicErrors . push ( error )
856856 return
@@ -880,7 +880,7 @@ export function trackDynamicHoleInNavigation(
880880 const error = createErrorWithComponentOrOwnerStack (
881881 message ,
882882 componentStack ,
883- dynamicValidation . debugInstantStack
883+ dynamicValidation . createInstantStack
884884 )
885885 dynamicValidation . validationPreventingErrors . push ( error )
886886 return
@@ -920,8 +920,11 @@ export function trackDynamicHoleInNavigation(
920920 if ( clientDynamic . syncDynamicErrorWithStack ) {
921921 // This task was the task that called the sync error.
922922 const syncError = clientDynamic . syncDynamicErrorWithStack
923- if ( dynamicValidation . debugInstantStack && syncError . cause === undefined ) {
924- syncError . cause = dynamicValidation . debugInstantStack
923+ if (
924+ dynamicValidation . createInstantStack !== null &&
925+ syncError . cause === undefined
926+ ) {
927+ syncError . cause = dynamicValidation . createInstantStack ( )
925928 }
926929 dynamicValidation . dynamicErrors . push ( syncError )
927930 return
@@ -935,7 +938,7 @@ export function trackDynamicHoleInNavigation(
935938 const error = createErrorWithComponentOrOwnerStack (
936939 message ,
937940 componentStack ,
938- dynamicValidation . debugInstantStack
941+ dynamicValidation . createInstantStack
939942 )
940943 dynamicValidation . dynamicErrors . push ( error )
941944 return
@@ -1083,14 +1086,15 @@ export function trackDynamicHoleInStaticShell(
10831086function createErrorWithComponentOrOwnerStack (
10841087 message : string ,
10851088 componentStack : string ,
1086- cause : Error | null
1089+ createInstantStack : ( ( ) => Error ) | null
10871090) {
10881091 const ownerStack =
10891092 process . env . NODE_ENV !== 'production' && React . captureOwnerStack
10901093 ? React . captureOwnerStack ( )
10911094 : null
10921095
1093- const error = new Error ( message , cause !== null ? { cause } : { } )
1096+ const cause = createInstantStack !== null ? createInstantStack ( ) : null
1097+ const error = new Error ( message , cause !== null ? { cause } : undefined )
10941098 // TODO go back to owner stack here if available. This is temporarily using componentStack to get the right
10951099 //
10961100 error . stack = error . name + ': ' + message + ( ownerStack || componentStack )
@@ -1245,31 +1249,29 @@ export function getNavigationDisallowedDynamicReasons(
12451249 }
12461250
12471251 if ( boundaryState . renderedIds . size < boundaryState . expectedIds . size ) {
1248- const { thrownErrorsOutsideBoundary, debugInstantStack } = dynamicValidation
1249- const causeOption = debugInstantStack ? { cause : debugInstantStack } : { }
1252+ const { thrownErrorsOutsideBoundary, createInstantStack } =
1253+ dynamicValidation
12501254 if ( thrownErrorsOutsideBoundary . length === 0 ) {
1251- return [
1252- new Error (
1253- `Route " ${ workStore . route } ": Could not validate \`unstable_instant\` because the target segment was prevented from rendering for an unknown reason.` ,
1254- causeOption
1255- ) ,
1256- ]
1255+ const message = `Route " ${ workStore . route } ": Could not validate \`unstable_instant\` because the target segment was prevented from rendering for an unknown reason.`
1256+ const error =
1257+ createInstantStack !== null ? createInstantStack ( ) : new Error ( )
1258+ error . name = 'Error'
1259+ error . message = message
1260+ return [ error ]
12571261 } else if ( thrownErrorsOutsideBoundary . length === 1 ) {
1258- return [
1259- new Error (
1260- `Route "${ workStore . route } ": Could not validate \`unstable_instant\` because the target segment was prevented from rendering, likely due to the following error.` ,
1261- causeOption
1262- ) ,
1263- thrownErrorsOutsideBoundary [ 0 ] as Error ,
1264- ]
1262+ const message = `Route "${ workStore . route } ": Could not validate \`unstable_instant\` because the target segment was prevented from rendering, likely due to the following error.`
1263+ const error =
1264+ createInstantStack !== null ? createInstantStack ( ) : new Error ( )
1265+ error . name = 'Error'
1266+ error . message = message
1267+ return [ error , thrownErrorsOutsideBoundary [ 0 ] as Error ]
12651268 } else {
1266- return [
1267- new Error (
1268- `Route "${ workStore . route } ": Could not validate \`unstable_instant\` because the target segment was prevented from rendering, likely due to one of the following errors.` ,
1269- causeOption
1270- ) ,
1271- ...( thrownErrorsOutsideBoundary as Error [ ] ) ,
1272- ]
1269+ const message = `Route "${ workStore . route } ": Could not validate \`unstable_instant\` because the target segment was prevented from rendering, likely due to one of the following errors.`
1270+ const error =
1271+ createInstantStack !== null ? createInstantStack ( ) : new Error ( )
1272+ error . name = 'Error'
1273+ error . message = message
1274+ return [ error , ...( thrownErrorsOutsideBoundary as Error [ ] ) ]
12731275 }
12741276 }
12751277
0 commit comments