diff --git a/packages/react-native/Libraries/LogBox/Data/__tests__/parseLogBoxLog-test.js b/packages/react-native/Libraries/LogBox/Data/__tests__/parseLogBoxLog-test.js index 895ccf57ec5..8de9a84f326 100644 --- a/packages/react-native/Libraries/LogBox/Data/__tests__/parseLogBoxLog-test.js +++ b/packages/react-native/Libraries/LogBox/Data/__tests__/parseLogBoxLog-test.js @@ -112,6 +112,36 @@ describe('parseLogBoxLog', () => { }); }); + it('does not duplicate message if component stack found but not parsed', () => { + expect( + parseLogBoxLog([ + 'Warning: Each child in a list should have a unique "key" prop.%s%s See https://fb.me/react-warning-keys for more information.%s', + '\n\nCheck the render method of `MyOtherComponent`.', + '', + '\n in\n in\n in', + ]), + ).toEqual({ + componentStackType: 'legacy', + componentStack: [], + category: + 'Warning: Each child in a list should have a unique "key" prop.%s%s See https://fb.me/react-warning-keys for more information.', + message: { + content: + 'Warning: Each child in a list should have a unique "key" prop.\n\nCheck the render method of `MyOtherComponent`. See https://fb.me/react-warning-keys for more information.', + substitutions: [ + { + length: 48, + offset: 62, + }, + { + length: 0, + offset: 110, + }, + ], + }, + }); + }); + it('detects a component stack in an interpolated warning', () => { expect( parseLogBoxLog([ diff --git a/packages/react-native/Libraries/LogBox/Data/parseLogBoxLog.js b/packages/react-native/Libraries/LogBox/Data/parseLogBoxLog.js index f4519b3eb57..af0bb5c2010 100644 --- a/packages/react-native/Libraries/LogBox/Data/parseLogBoxLog.js +++ b/packages/react-native/Libraries/LogBox/Data/parseLogBoxLog.js @@ -462,7 +462,7 @@ export function parseLogBoxLog(args: $ReadOnlyArray): {| } } - if (componentStack.length === 0) { + if (componentStack.length === 0 && argsWithoutComponentStack.length === 0) { // Try finding the component stack elsewhere. for (const arg of args) { if (typeof arg === 'string' && isComponentStack(arg)) {