Skip to content

Commit 32c3cd3

Browse files
gaearonfacebook-github-bot
authored andcommitted
Fix junk in React warnings in Logbox (facebook#44812)
Summary: Before all React errors showed junk like this: ![Screenshot 2024-06-06 at 06 24 38](https://github.com/facebook/react-native/assets/810438/40be3133-e31d-43e8-b04d-ffbc5b462027) This is because `isComponentStack` detected a component stack but `parseComponentStack` couldn't actually parse it (it doesn't deal with React's current format like `in Foo (created by FeedItemInner)`) so `componentStack` was an empty array, resulting in the next block of code pushing stuff into `argsWithoutComponentStack` _again_, thus repeating its args. The fix is not to do that. Result on my local copy: ![Screenshot 2024-06-06 at 06 24 24](https://github.com/facebook/react-native/assets/810438/8f3d32d9-6f28-472c-be34-c802a0e2f161) Ofc this doesn't actually show the component stack but that was broken before too. I edited in-place in my `node_modules` so I haven't verified this 100% works on main. Hope this is useful! ## Changelog: [General] [Fixed] - Remove accidental duplication in React warnings in Logbox Pull Request resolved: facebook#44812 Reviewed By: cortinico Differential Revision: D58240357 Pulled By: rickhanlonii fbshipit-source-id: b6ecb659d3b393e497caf5e7b2087a8e529f1b28
1 parent 2a0a112 commit 32c3cd3

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

packages/react-native/Libraries/LogBox/Data/__tests__/parseLogBoxLog-test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,36 @@ describe('parseLogBoxLog', () => {
112112
});
113113
});
114114

115+
it('does not duplicate message if component stack found but not parsed', () => {
116+
expect(
117+
parseLogBoxLog([
118+
'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',
119+
'\n\nCheck the render method of `MyOtherComponent`.',
120+
'',
121+
'\n in\n in\n in',
122+
]),
123+
).toEqual({
124+
componentStackType: 'legacy',
125+
componentStack: [],
126+
category:
127+
'Warning: Each child in a list should have a unique "key" prop.%s%s See https://fb.me/react-warning-keys for more information.',
128+
message: {
129+
content:
130+
'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.',
131+
substitutions: [
132+
{
133+
length: 48,
134+
offset: 62,
135+
},
136+
{
137+
length: 0,
138+
offset: 110,
139+
},
140+
],
141+
},
142+
});
143+
});
144+
115145
it('detects a component stack in an interpolated warning', () => {
116146
expect(
117147
parseLogBoxLog([

packages/react-native/Libraries/LogBox/Data/parseLogBoxLog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ export function parseLogBoxLog(args: $ReadOnlyArray<mixed>): {|
462462
}
463463
}
464464

465-
if (componentStack.length === 0) {
465+
if (componentStack.length === 0 && argsWithoutComponentStack.length === 0) {
466466
// Try finding the component stack elsewhere.
467467
for (const arg of args) {
468468
if (typeof arg === 'string' && isComponentStack(arg)) {

0 commit comments

Comments
 (0)