Skip to content
3 changes: 2 additions & 1 deletion packages/react-native/Libraries/LogBox/Data/LogBoxData.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type LogData = $ReadOnly<{|
message: Message,
category: Category,
componentStack: ComponentStack,
stack?: string,
|}>;

export type Observer = (
Expand Down Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import typeof {enable} from 'promise/setimmediate/rejection-tracking';

import LogBox from './LogBox/LogBox';

let rejectionTrackingOptions: $NonMaybeType<Parameters<enable>[0]> = {
allRejections: true,
onUnhandled: (id, rejection = {}) => {
Expand All @@ -22,7 +24,26 @@ let rejectionTrackingOptions: $NonMaybeType<Parameters<enable>[0]> = {
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
message = Error.prototype.toString.call(rejection);
const error: Error = (rejection: $FlowFixMe);
stack = error.stack;

// Print correct unhandled rejections stack while on DEV
if (__DEV__) {
LogBox.addLog({
level: 'warn',
message: {
content:
`Possible Unhandled Promise Rejection (id: ${id}):\n` +
`${message ?? ''}\n`,
substitutions: [],
},
componentStack: [],
stack: error.stack,
category: 'possible_unhandled_promise_rejection',
});

return;
} else {
stack = error.stack;
}
} else {
try {
message = require('pretty-format')(rejection);
Expand Down