mirror of
https://github.com/zebrajr/react.git
synced 2025-12-07 00:20:28 +01:00
We still filter them before passing from server to client in Flight Server but when presenting a native stack, we don't need to filter them. That's left to ignore listing in the presentation. The stacks are pretty clean regardless thanks to the bottom stack frames. We can also unify the owner stack formatters into one shared module since Fizz/Flight/Fiber all do the same thing. DevTools currently does the same thing but is forked so it can support multiple versions.
41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
*/
|
|
|
|
export function formatOwnerStack(error: Error): string {
|
|
const prevPrepareStackTrace = Error.prepareStackTrace;
|
|
// $FlowFixMe[incompatible-type] It does accept undefined.
|
|
Error.prepareStackTrace = undefined;
|
|
let stack = error.stack;
|
|
Error.prepareStackTrace = prevPrepareStackTrace;
|
|
if (stack.startsWith('Error: react-stack-top-frame\n')) {
|
|
// V8's default formatting prefixes with the error message which we
|
|
// don't want/need.
|
|
stack = stack.slice(29);
|
|
}
|
|
let idx = stack.indexOf('\n');
|
|
if (idx !== -1) {
|
|
// Pop the JSX frame.
|
|
stack = stack.slice(idx + 1);
|
|
}
|
|
idx = stack.indexOf('react-stack-bottom-frame');
|
|
if (idx !== -1) {
|
|
idx = stack.lastIndexOf('\n', idx);
|
|
}
|
|
if (idx !== -1) {
|
|
// Cut off everything after the bottom frame since it'll be internals.
|
|
stack = stack.slice(0, idx);
|
|
} else {
|
|
// We didn't find any internal callsite out to user space.
|
|
// This means that this was called outside an owner or the owner is fully internal.
|
|
// To keep things light we exclude the entire trace in this case.
|
|
return '';
|
|
}
|
|
return stack;
|
|
}
|