Skip to content

Commit 86920e8

Browse files
committed
Run recreated Errors within a fake native stack
1 parent 8854c33 commit 86920e8

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

packages/react-client/src/ReactFlightClient.js

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,12 +1586,40 @@ function resolveErrorDev(
15861586
'resolveErrorDev should never be called in production mode. Use resolveErrorProd instead. This is a bug in React.',
15871587
);
15881588
}
1589-
// eslint-disable-next-line react-internal/prod-error-codes
1590-
const error = new Error(
1591-
message ||
1592-
'An error occurred in the Server Components render but no message was provided',
1593-
);
1594-
error.stack = stack;
1589+
1590+
let error;
1591+
if (!enableOwnerStacks) {
1592+
// Executing Error within a native stack isn't really limited to owner stacks
1593+
// but we gate it behind the same flag for now while iterating.
1594+
// eslint-disable-next-line react-internal/prod-error-codes
1595+
error = Error(
1596+
message ||
1597+
'An error occurred in the Server Components render but no message was provided',
1598+
);
1599+
error.stack = stack;
1600+
} else {
1601+
const callStack = buildFakeCallStack(
1602+
response,
1603+
stack,
1604+
// $FlowFixMe[incompatible-use]
1605+
Error.bind(
1606+
null,
1607+
message ||
1608+
'An error occurred in the Server Components render but no message was provided',
1609+
),
1610+
);
1611+
const rootTask = response._debugRootTask;
1612+
if (rootTask != null) {
1613+
error = rootTask.run(callStack);
1614+
} else {
1615+
error = callStack();
1616+
}
1617+
// Overriding the stack isn't really necessary at this point and maybe we should just
1618+
// leave the native one. However, the native one gets printed unsource mapped with
1619+
// reportError. If that's fixed it might be better to use the native one.
1620+
error.stack = stack;
1621+
}
1622+
15951623
(error: any).digest = digest;
15961624
const errorWithDigest: ErrorWithDigest = (error: any);
15971625
const chunks = response._chunks;

0 commit comments

Comments
 (0)