@@ -1209,16 +1209,15 @@ function validateIterable(iterable, iteratorFn: Function): void {
1209
1209
}
1210
1210
}
1211
1211
1212
- let renderNodeDestructive = renderNodeDestructiveImpl ;
1213
- if ( __DEV__ ) {
1214
- // In Dev we wrap renderNodeDestructiveImpl in a try / catch so we can capture
1215
- // a component stack at the right place in the tree. We don't do this in renderNode
1216
- // becuase it is not called at every layer of the tree and we may lose frames
1217
- renderNodeDestructive = (
1218
- request : Request ,
1219
- task : Task ,
1220
- node : ReactNodeList ,
1221
- ) : void => {
1212
+ function renderNodeDestructive (
1213
+ request : Request ,
1214
+ task : Task ,
1215
+ node : ReactNodeList ,
1216
+ ) : void {
1217
+ if ( __DEV__ ) {
1218
+ // In Dev we wrap renderNodeDestructiveImpl in a try / catch so we can capture
1219
+ // a component stack at the right place in the tree. We don't do this in renderNode
1220
+ // becuase it is not called at every layer of the tree and we may lose frames
1222
1221
try {
1223
1222
return renderNodeDestructiveImpl ( request , task , node ) ;
1224
1223
} catch ( x ) {
@@ -1234,7 +1233,9 @@ if (__DEV__) {
1234
1233
// rethrow so normal suspense logic can handle thrown value accordingly
1235
1234
throw x ;
1236
1235
}
1237
- } ;
1236
+ } else {
1237
+ return renderNodeDestructiveImpl ( request , task , node ) ;
1238
+ }
1238
1239
}
1239
1240
1240
1241
// This function by it self renders a node and consumes the task by mutating it
@@ -1271,16 +1272,22 @@ function renderNodeDestructiveImpl(
1271
1272
const init = lazyNode . _init ;
1272
1273
let resolvedNode ;
1273
1274
if ( __DEV__ ) {
1274
- // If a lazy element throws a componentStack frame will be popped but since
1275
- // it is an element and not a component it never added a frame. We
1276
- // add a fake frame here in case we throw and then remove it if we didn't
1277
- // @TODO decide if this frame showing up in dev component stacks is good
1278
- // Currently if a lazy element rejects the component stack will include this
1279
- // special frame. My current intuition is this is good and will aid in identifying
1280
- // where errors are happening.
1281
- pushBuiltInComponentStackInDEV ( task , '~lazy-element~' ) ;
1282
- resolvedNode = init ( payload ) ;
1283
- popComponentStackInDEV ( task ) ;
1275
+ try {
1276
+ resolvedNode = init ( payload ) ;
1277
+ } catch ( x ) {
1278
+ if (
1279
+ typeof x === 'object' &&
1280
+ x !== null &&
1281
+ typeof x . then === 'function'
1282
+ ) {
1283
+ // this Lazy initializer is suspending. push a temporary frame onto the stack so it can be
1284
+ // popped off in spawnNewSuspendedTask. This aligns stack behavior between Lazy in element position
1285
+ // vs Component position. We do not want the frame for Errors so we exclusively do this in
1286
+ // the wakeable branch
1287
+ pushBuiltInComponentStackInDEV ( task , 'Lazy' ) ;
1288
+ }
1289
+ throw x ;
1290
+ }
1284
1291
} else {
1285
1292
resolvedNode = init ( payload ) ;
1286
1293
}
0 commit comments