diff --git a/packages/react-native/Libraries/LogBox/Data/LogBoxData.js b/packages/react-native/Libraries/LogBox/Data/LogBoxData.js index d3e06b0451303c..abc2401ac42159 100644 --- a/packages/react-native/Libraries/LogBox/Data/LogBoxData.js +++ b/packages/react-native/Libraries/LogBox/Data/LogBoxData.js @@ -30,6 +30,7 @@ export type LogData = $ReadOnly<{| message: Message, category: Category, componentStack: ComponentStack, + stack?: string, |}>; export type Observer = ( @@ -198,7 +199,7 @@ export function addLog(log: LogData): void { // otherwise spammy logs would pause rendering. setImmediate(() => { try { - const stack = parseErrorStack(errorForStackTrace?.stack); + const stack = parseErrorStack(log.stack ?? errorForStackTrace?.stack); appendNewLog( new LogBoxLog({ diff --git a/packages/react-native/Libraries/promiseRejectionTrackingOptions.js b/packages/react-native/Libraries/promiseRejectionTrackingOptions.js index b951f612ecf6c7..5f9c9a1dafd880 100644 --- a/packages/react-native/Libraries/promiseRejectionTrackingOptions.js +++ b/packages/react-native/Libraries/promiseRejectionTrackingOptions.js @@ -10,6 +10,8 @@ import typeof {enable} from 'promise/setimmediate/rejection-tracking'; +import LogBox from './LogBox/LogBox'; + let rejectionTrackingOptions: $NonMaybeType[0]> = { allRejections: true, onUnhandled: (id, rejection = {}) => { @@ -34,17 +36,29 @@ let rejectionTrackingOptions: $NonMaybeType[0]> = { } } - const warning = - `Possible Unhandled Promise Rejection (id: ${id}):\n` + - `${message ?? ''}\n` + - (stack == null ? '' : stack); - console.warn(warning); + const warning = `Possible unhandled promise rejection (id: ${id}):\n${ + message ?? '' + }`; + if (__DEV__) { + LogBox.addLog({ + level: 'warn', + message: { + content: warning, + substitutions: [], + }, + componentStack: [], + stack, + category: 'possible_unhandled_promise_rejection', + }); + } else { + console.warn(warning); + } }, onHandled: id => { const warning = - `Promise Rejection Handled (id: ${id})\n` + + `Promise rejection handled (id: ${id})\n` + 'This means you can ignore any previous messages of the form ' + - `"Possible Unhandled Promise Rejection (id: ${id}):"`; + `"Possible unhandled promise rejection (id: ${id}):"`; console.warn(warning); }, };