From 409e3f50dc1a15c4fadb2e6ef39c84c0ab3de181 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 6 Jun 2024 06:24:08 +0100 Subject: [PATCH 1/3] Fix logbox --- packages/react-native/Libraries/LogBox/Data/parseLogBoxLog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-native/Libraries/LogBox/Data/parseLogBoxLog.js b/packages/react-native/Libraries/LogBox/Data/parseLogBoxLog.js index f4519b3eb574ea..af0bb5c20101dd 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)) { From 29d21bc168a07588ffffbad17dd89c65a8212854 Mon Sep 17 00:00:00 2001 From: Rick Hanlon Date: Thu, 6 Jun 2024 10:58:04 -0400 Subject: [PATCH 2/3] Add test --- .../Data/__tests__/parseLogBoxLog-test.js | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) 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 895ccf57ec50f4..723f7054e277d5 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,37 @@ 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([ From 8e7f4e60b1b92eb81b6dd3c9ae287ebc53442f0d Mon Sep 17 00:00:00 2001 From: Rick Hanlon Date: Thu, 6 Jun 2024 11:14:57 -0400 Subject: [PATCH 3/3] prettier --- .../Libraries/LogBox/Data/__tests__/parseLogBoxLog-test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 723f7054e277d5..8de9a84f3266ec 100644 --- a/packages/react-native/Libraries/LogBox/Data/__tests__/parseLogBoxLog-test.js +++ b/packages/react-native/Libraries/LogBox/Data/__tests__/parseLogBoxLog-test.js @@ -122,8 +122,7 @@ describe('parseLogBoxLog', () => { ]), ).toEqual({ componentStackType: 'legacy', - componentStack: [ - ], + 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: {