-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
101 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 3 additions & 15 deletions
18
packages/next/src/client/components/react-dev-overlay/internal/helpers/stitched-error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...s/next/src/client/components/react-dev-overlay/internal/helpers/strip-stack-frame.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { stripStackByFrame } from './strip-stack-frame' | ||
|
||
describe('stripStackByFrame', () => { | ||
it('strips stack after frame', () => { | ||
const stripStackByFrameBefore = (stack: string) => | ||
stripStackByFrame(stack, 'special-stack-frame', true) | ||
|
||
const stack = `Error: test | ||
at page (http://localhost:3000/_next/static/chunks/webpack.js:1:1) | ||
at special-stack-frame (http://localhost:3000/_next/static/chunks/webpack.js:1:1) | ||
at foo (http://localhost:3000/_next/static/chunks/webpack.js:1:1) | ||
` | ||
|
||
const strippedStack = stripStackByFrameBefore(stack) | ||
expect(strippedStack).toMatchInlineSnapshot(` | ||
"Error: test | ||
at page (http://localhost:3000/_next/static/chunks/webpack.js:1:1)" | ||
`) | ||
}) | ||
|
||
it('strips stack before frame', () => { | ||
const stripStackByFrameAfter = (stack: string) => | ||
stripStackByFrame(stack, 'special-stack-frame', false) | ||
|
||
const stack = `Error: test | ||
at page (http://localhost:3000/_next/static/chunks/webpack.js:1:1) | ||
at special-stack-frame (http://localhost:3000/_next/static/chunks/webpack.js:1:1) | ||
at foo (http://localhost:3000/_next/static/chunks/webpack.js:1:1) | ||
` | ||
|
||
const strippedStack = stripStackByFrameAfter(stack) | ||
expect(strippedStack).toMatchInlineSnapshot(` | ||
" at foo (http://localhost:3000/_next/static/chunks/webpack.js:1:1) | ||
" | ||
`) | ||
}) | ||
}) |
21 changes: 21 additions & 0 deletions
21
packages/next/src/client/components/react-dev-overlay/internal/helpers/strip-stack-frame.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export function stripStackByFrame( | ||
stack: string, | ||
framePivot: string, | ||
stripAfter: boolean | ||
): string { | ||
const framePivotRegex = new RegExp(`(at ${framePivot} )|(${framePivot}\\@)`) | ||
const stackLines = stack.split('\n') | ||
const indexOfSplit = stackLines.findIndex((line) => | ||
framePivotRegex.test(line) | ||
) | ||
const isOriginalReactError = indexOfSplit >= 0 // has the frame pivot | ||
const strippedStack = isOriginalReactError | ||
? stripAfter | ||
? // Keep the frames before pivot | ||
stackLines.slice(0, indexOfSplit).join('\n') | ||
: // Keep the frames after pivot | ||
stackLines.slice(indexOfSplit + 1).join('\n') | ||
: stack | ||
|
||
return strippedStack | ||
} |