Skip to content

Commit 967ef32

Browse files
rickhanloniifacebook-github-bot
authored andcommitted
Add support for owner stacks (#48782)
Summary: Pull Request resolved: #48782 React currently has a babel transform to replace all `console.error` calls with a special function for RN and www. The function adds component stacks, which doesn't make sense in an owner stack world because: - not all console.error calls are replaced, creating inconsistency - oss web users don't append component stacks to console.log any more - component stacks can be accessed for DEV modals like logbox with `captureOwnerStack` - owner stacks are already added to the console with createTask if you use console.error directly - the redirection is the single greatest source of fragility in the logbox reporting pipeline So we're removing this as part of the owner stack rollout. This should only be enabled with owner stacks. ## Example Screen Before: {F1974436644} After: {F1974436645} ## Changelog: [General] [Added] - Add full owner stack support to React Native Reviewed By: hoxyq Differential Revision: D68285628 fbshipit-source-id: 9772593d7ac6e012392d18c6796580c14c852074
1 parent 1536a7f commit 967ef32

File tree

1 file changed

+13
-1
lines changed
  • packages/react-native/Libraries/LogBox

1 file changed

+13
-1
lines changed

packages/react-native/Libraries/LogBox/LogBox.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {ExtendedExceptionData} from './Data/parseLogBoxLog';
1414
import Platform from '../Utilities/Platform';
1515
import RCTLog from '../Utilities/RCTLog';
1616
import {hasComponentStack} from './Data/parseLogBoxLog';
17+
import * as React from 'react';
1718

1819
export type {LogData, ExtendedExceptionData, IgnorePattern};
1920

@@ -192,9 +193,20 @@ if (__DEV__) {
192193
}
193194

194195
try {
196+
let stack;
197+
// $FlowFixMe[prop-missing] Not added to flow types yet.
198+
if (!hasComponentStack(args) && React.captureOwnerStack != null) {
199+
stack = React.captureOwnerStack();
200+
if (!hasComponentStack(args)) {
201+
if (stack !== '') {
202+
args[0] = args[0] += '%s';
203+
args.push(stack);
204+
}
205+
}
206+
}
195207
if (!isWarningModuleWarning(...args) && !hasComponentStack(args)) {
196208
// Only show LogBox for the 'warning' module, or React errors with
197-
// component stacks, otherwise pass the error through.u
209+
// component stacks, otherwise pass the error through.
198210
//
199211
// By passing through, this will get picked up by the React console override,
200212
// potentially adding the component stack. React then passes it back to the

0 commit comments

Comments
 (0)