mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix junk in React warnings in Logbox (#44812)
Summary: Before all React errors showed junk like this:  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:  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: https://github.com/facebook/react-native/pull/44812 Reviewed By: cortinico Differential Revision: D58240357 Pulled By: rickhanlonii fbshipit-source-id: b6ecb659d3b393e497caf5e7b2087a8e529f1b28
This commit is contained in:
@@ -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([
|
||||
|
||||
@@ -462,7 +462,7 @@ export function parseLogBoxLog(args: $ReadOnlyArray<mixed>): {|
|
||||
}
|
||||
}
|
||||
|
||||
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)) {
|
||||
|
||||
Reference in New Issue
Block a user