@@ -1105,8 +1105,8 @@ function pushComponentStack(task: Task): void {
11051105function createComponentStackFromType (
11061106 parent : null | ComponentStackNode ,
11071107 type : Function | string | symbol ,
1108- owner : null | ReactComponentInfo | ComponentStackNode , // DEV only
1109- stack : null | Error , // DEV only
1108+ owner : void | null | ReactComponentInfo | ComponentStackNode , // DEV only
1109+ stack : void | null | string | Error , // DEV only
11101110) : ComponentStackNode {
11111111 if ( __DEV__ ) {
11121112 return {
@@ -1122,6 +1122,20 @@ function createComponentStackFromType(
11221122 } ;
11231123}
11241124
1125+ function replaceSuspenseComponentStackWithSuspenseFallbackStack (
1126+ componentStack : null | ComponentStackNode ,
1127+ ) : null | ComponentStackNode {
1128+ if ( componentStack === null ) {
1129+ return null ;
1130+ }
1131+ return createComponentStackFromType (
1132+ componentStack . parent ,
1133+ 'Suspense Fallback' ,
1134+ __DEV__ ? componentStack . owner : null ,
1135+ __DEV__ ? componentStack . stack : null ,
1136+ ) ;
1137+ }
1138+
11251139type ThrownInfo = {
11261140 componentStack ?: string ,
11271141} ;
@@ -1350,6 +1364,8 @@ function renderSuspenseBoundary(
13501364 contentRootSegment.parentFlushed = true;
13511365
13521366 if (request.trackedPostpones !== null) {
1367+ // Stash the original stack frame.
1368+ const suspenseComponentStack = task . componentStack ;
13531369 // This is a prerender. In this mode we want to render the fallback synchronously and schedule
13541370 // the content to render later. This is the opposite of what we do during a normal render
13551371 // where we try to skip rendering the fallback if the content itself can render synchronously
@@ -1374,6 +1390,10 @@ function renderSuspenseBoundary(
13741390 request . resumableState ,
13751391 prevContext ,
13761392 ) ;
1393+ task . componentStack =
1394+ replaceSuspenseComponentStackWithSuspenseFallbackStack (
1395+ suspenseComponentStack ,
1396+ ) ;
13771397 boundarySegment . status = RENDERING ;
13781398 try {
13791399 renderNode ( request , task , fallback , - 1 ) ;
@@ -1419,7 +1439,7 @@ function renderSuspenseBoundary(
14191439 task . context ,
14201440 task . treeContext ,
14211441 null , // The row gets reset inside the Suspense boundary.
1422- task . componentStack ,
1442+ suspenseComponentStack ,
14231443 ! disableLegacyContext ? task . legacyContext : emptyContextObject ,
14241444 __DEV__ ? task . debugTask : null ,
14251445 ) ;
@@ -1572,7 +1592,9 @@ function renderSuspenseBoundary(
15721592 task . context ,
15731593 task . treeContext ,
15741594 task . row ,
1575- task . componentStack ,
1595+ replaceSuspenseComponentStackWithSuspenseFallbackStack (
1596+ task . componentStack ,
1597+ ) ,
15761598 ! disableLegacyContext ? task . legacyContext : emptyContextObject ,
15771599 __DEV__ ? task . debugTask : null ,
15781600 ) ;
@@ -1744,7 +1766,7 @@ function replaySuspenseBoundary(
17441766 task . context ,
17451767 task . treeContext ,
17461768 task . row ,
1747- task . componentStack ,
1769+ replaceSuspenseComponentStackWithSuspenseFallbackStack ( task . componentStack ) ,
17481770 ! disableLegacyContext ? task . legacyContext : emptyContextObject ,
17491771 __DEV__ ? task . debugTask : null ,
17501772 ) ;
0 commit comments