diff --git a/packages/react-native/Libraries/Core/Devtools/parseHermesStack.js b/packages/react-native/Libraries/Core/Devtools/parseHermesStack.js index f7b6929834b..d39a69c9637 100644 --- a/packages/react-native/Libraries/Core/Devtools/parseHermesStack.js +++ b/packages/react-native/Libraries/Core/Devtools/parseHermesStack.js @@ -72,6 +72,7 @@ const RE_FRAME = // Capturing groups: // 1. count of skipped frames const RE_SKIPPED = /^ {4}... skipping (\d+) frames$/; +const RE_COMPONENT_NO_STACK = /^ {4}at .*$/; function isInternalBytecodeSourceUrl(sourceUrl: string): boolean { // See https://github.com/facebook/hermes/blob/3332fa020cae0bab751f648db7c94e1d687eeec7/lib/VM/Runtime.cpp#L1100 @@ -132,6 +133,11 @@ module.exports = function parseHermesStack(stack: string): HermesParsedStack { entries.push(entry); continue; } + if (RE_COMPONENT_NO_STACK.test(line)) { + // Skip component stacks without source location. + // TODO: This will not be displayed, not sure how to handle it. + continue; + } // No match - we're still in the message lastMessageLine = i; entries = []; 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 3035f76a908..e2773b28d73 100644 --- a/packages/react-native/Libraries/LogBox/Data/__tests__/parseLogBoxLog-test.js +++ b/packages/react-native/Libraries/LogBox/Data/__tests__/parseLogBoxLog-test.js @@ -993,14 +993,25 @@ Please follow the instructions at: fburl.com/rn-remote-assets`, }); }); - describe('Handles component stack frames formatted as call stacks', () => { + describe('Handles component stack frames formatted as call stacks in Hermes', () => { + let originalHermesInternal; + beforeEach(() => { + originalHermesInternal = global.HermesInternal; + // $FlowFixMe[cannot-write] - Jest + global.HermesInternal = true; + }); + afterEach(() => { + // $FlowFixMe[cannot-write] - Jest + global.HermesInternal = originalHermesInternal; + }); + // In new versions of React, the component stack frame format changed to match call stacks. it('detects a component stack in an interpolated warning', () => { expect( parseLogBoxLog([ 'Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?%s%s', '\n\nCheck the render method of `MyComponent`.', - '\n at MyComponent (/path/to/filename.js:1:2)\n at MyOtherComponent\n at MyAppComponent (/path/to/app.js:100:20)', + '\n at MyComponent (/path/to/filename.js:1:2)\n at MyOtherComponent\n at MyAppComponent (/path/to/app.js:100:20)', ]), ).toEqual({ componentStack: [ @@ -1037,7 +1048,7 @@ Please follow the instructions at: fburl.com/rn-remote-assets`, it('detects a component stack in the first argument', () => { expect( parseLogBoxLog([ - 'Some kind of message\n at MyComponent (/path/to/filename.js:1:2)\n at MyOtherComponent\n at MyAppComponent (/path/to/app.js:100:20)', + 'Some kind of message\n at MyComponent (/path/to/filename.js:1:2)\n at MyOtherComponent\n at MyAppComponent (/path/to/app.js:100:20)', ]), ).toEqual({ componentStack: [ @@ -1068,7 +1079,7 @@ Please follow the instructions at: fburl.com/rn-remote-assets`, expect( parseLogBoxLog([ 'Some kind of message', - '\n at MyComponent (/path/to/filename.js:1:2)\n at MyOtherComponent\n at MyAppComponent (/path/to/app.js:100:20)', + '\n at MyComponent (/path/to/filename.js:1:2)\n at MyOtherComponent\n at MyAppComponent (/path/to/app.js:100:20)', ]), ).toEqual({ componentStack: [ @@ -1101,7 +1112,7 @@ Please follow the instructions at: fburl.com/rn-remote-assets`, '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 at MyComponent (/path/to/filename.js:1:2)\n at MyOtherComponent\n at MyAppComponent (/path/to/app.js:100:20)', + '\n at MyComponent (/path/to/filename.js:1:2)\n at MyOtherComponent\n at MyAppComponent (/path/to/app.js:100:20)', ]), ).toEqual({ componentStack: [ @@ -1148,7 +1159,7 @@ Please follow the instructions at: fburl.com/rn-remote-assets`, originalMessage: '### Error', name: '', componentStack: - '\n at MyComponent (/path/to/filename.js:1:2)\n at MyOtherComponent\n at MyAppComponent (/path/to/app.js:100:20)', + '\n at MyComponent (/path/to/filename.js:1:2)\n at MyOtherComponent\n at MyAppComponent (/path/to/app.js:100:20)', stack: [ { column: 1,