Skip to content

Commit c026c26

Browse files
committed
nits
1 parent 3fc4439 commit c026c26

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

packages/react-server/src/ReactFizzServer.js

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,16 +1209,15 @@ function validateIterable(iterable, iteratorFn: Function): void {
12091209
}
12101210
}
12111211

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
12221221
try {
12231222
return renderNodeDestructiveImpl(request, task, node);
12241223
} catch (x) {
@@ -1234,7 +1233,9 @@ if (__DEV__) {
12341233
// rethrow so normal suspense logic can handle thrown value accordingly
12351234
throw x;
12361235
}
1237-
};
1236+
} else {
1237+
return renderNodeDestructiveImpl(request, task, node);
1238+
}
12381239
}
12391240

12401241
// This function by it self renders a node and consumes the task by mutating it
@@ -1271,16 +1272,22 @@ function renderNodeDestructiveImpl(
12711272
const init = lazyNode._init;
12721273
let resolvedNode;
12731274
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+
}
12841291
} else {
12851292
resolvedNode = init(payload);
12861293
}

0 commit comments

Comments
 (0)