1586
'resolveErrorDev should never be called in production mode. Use resolveErrorProd instead. This is a bug in React.',
1587
);
1588
}
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
+ }
1618
+
1619
(error: any).digest = digest;
1620
const errorWithDigest: ErrorWithDigest = (error: any);
1621
const chunks = response._chunks;
1701
? new Map()
1702
: (null: any);
1703
1704
+let fakeFunctionIdx = 0;
1705
function createFakeFunction<T>(
1706
name: string,
1707
filename: string,
1720
// point to the original source.
1721
let code;
1722
if (line <= 1) {
1698
- code = '_=>' + ' '.repeat(col < 4 ? 0 : col - 4) + '_()\n' + comment + '\n';
1723
+ code = '_=>' + ' '.repeat(col < 4 ? 0 : col - 4) + '_()\n' + comment;
1724
} else {
1725
code =
1726
comment +
1727
'\n'.repeat(line - 2) +
1728
'_=>\n' +
1729
' '.repeat(col < 1 ? 0 : col - 1) +
1705
- '_()\n';
1730
+ '_()';
1731
+ }
1732
+
1733
+ if (filename.startsWith('/')) {
1734
+ // If the filename starts with `/` we assume that it is a file system file
1735
+ // rather than relative to the current host. Since on the server fully qualified
1736
+ // stack traces use the file path.
1737
+ // TODO: What does this look like on Windows?
1738
+ filename = 'file://' + filename;
1739
}
1740
1741
if (sourceMap) {
1709
- code += '//# sourceMappingURL=' + sourceMap;
1742
+ // We use the prefix rsc://React/ to separate these from other files listed in
1743
+ // the Chrome DevTools. We need a "host name" and not just a protocol because
1744
+ // otherwise the group name becomes the root folder. Ideally we don't want to
1745
+ // show these at all but there's two reasons to assign a fake URL.
1746
+ // 1) A printed stack trace string needs a unique URL to be able to source map it.
1747
+ // 2) If source maps are disabled or fails, you should at least be able to tell
1748
+ // which file it was.
1749
+ code += '\n//# sourceURL=rsc://React/' + filename + '?' + fakeFunctionIdx++;
1750
+ code += '\n//# sourceMappingURL=' + sourceMap;
1751
} else if (filename) {
1711
- code += '//# sourceURL=' + filename;
1752
+ code += '\n//# sourceURL=' + filename;
1753
}
1754
1755
let fn: FakeFunction<T>;