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 a57f3666899d62..5f9c9a1dafd880 100644 --- a/packages/react-native/Libraries/promiseRejectionTrackingOptions.js +++ b/packages/react-native/Libraries/promiseRejectionTrackingOptions.js @@ -10,9 +10,9 @@ import typeof {enable} from 'promise/setimmediate/rejection-tracking'; -type ExtractOptionsType =

(((options?: ?P) => void)) => P; +import LogBox from './LogBox/LogBox'; -let rejectionTrackingOptions: $Call = { +let rejectionTrackingOptions: $NonMaybeType[0]> = { allRejections: true, onUnhandled: (id, rejection = {}) => { let message: string; @@ -36,17 +36,29 @@ let rejectionTrackingOptions: $Call = { } } - 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); }, };