Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
74b09dd0
Unverified
Commit
74b09dd0
authored
Dec 09, 2024
by
Jiachi Liu
Committed by
GitHub
Dec 09, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove ignore for anonymous stack frame (#73610)
parent
44317540
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
103 additions
and
88 deletions
+103
-88
stack-frame.ts
...ponents/react-dev-overlay/internal/helpers/stack-frame.ts
+0
-6
webpack-module-path.test.ts
...-dev-overlay/internal/helpers/webpack-module-path.test.ts
+0
-4
webpack-module-path.ts
...react-dev-overlay/internal/helpers/webpack-module-path.ts
+1
-4
ReactRefreshLogBox.test.ts
test/development/acceptance/ReactRefreshLogBox.test.ts
+8
-18
ReactRefreshLogBox.test.ts.snap
.../acceptance/__snapshots__/ReactRefreshLogBox.test.ts.snap
+14
-0
capture-console-error-owner-stack.test.ts
...ror-owner-stack/capture-console-error-owner-stack.test.ts
+13
-3
capture-console-error.test.ts
...p-dir/capture-console-error/capture-console-error.test.ts
+4
-2
index.test.ts
test/development/app-dir/dynamic-error-trace/index.test.ts
+9
-3
owner-stack-react-missing-key-prop.test.ts
...ssing-key-prop/owner-stack-react-missing-key-prop.test.ts
+54
-48
No files found.
packages/next/src/client/components/react-dev-overlay/internal/helpers/stack-frame.ts
View file @
74b09dd0
...
@@ -59,7 +59,6 @@ function getOriginalStackFrame(
...
@@ -59,7 +59,6 @@ function getOriginalStackFrame(
// TODO: merge this section into ignoredList handling
// TODO: merge this section into ignoredList handling
if
(
if
(
source
.
file
===
'<anonymous>'
||
source
.
file
===
'file://'
||
source
.
file
===
'file://'
||
source
.
file
?.
match
(
/^node:/
)
||
source
.
file
?.
match
(
/^node:/
)
||
source
.
file
?.
match
(
/https
?
:
\/\/
/
)
source
.
file
?.
match
(
/https
?
:
\/\/
/
)
...
@@ -136,11 +135,6 @@ export function getFrameSource(frame: StackFrame): string {
...
@@ -136,11 +135,6 @@ export function getFrameSource(frame: StackFrame): string {
}
}
if
(
!
isWebpackInternalResource
(
frame
.
file
)
&&
frame
.
lineNumber
!=
null
)
{
if
(
!
isWebpackInternalResource
(
frame
.
file
)
&&
frame
.
lineNumber
!=
null
)
{
// If the method name is replayed from server, e.g. Page [Server],
// and it's formatted to empty string, recover it as <anonymous> to display it.
if
(
!
str
&&
frame
.
methodName
.
endsWith
(
' [Server]'
))
{
str
=
'<anonymous>'
}
if
(
str
)
{
if
(
str
)
{
if
(
frame
.
column
!=
null
)
{
if
(
frame
.
column
!=
null
)
{
str
+=
` (
${
frame
.
lineNumber
}
:
${
frame
.
column
}
)`
str
+=
` (
${
frame
.
lineNumber
}
:
${
frame
.
column
}
)`
...
...
packages/next/src/client/components/react-dev-overlay/internal/helpers/webpack-module-path.test.ts
View file @
74b09dd0
...
@@ -82,9 +82,5 @@ describe('webpack-module-path', () => {
...
@@ -82,9 +82,5 @@ describe('webpack-module-path', () => {
'./src/hello.tsx'
'./src/hello.tsx'
)
)
})
})
it
(
'should return an empty string for <anonymous> file paths'
,
()
=>
{
expect
(
formatFrameSourceFile
(
'<anonymous>'
)).
toBe
(
''
)
})
})
})
})
})
packages/next/src/client/components/react-dev-overlay/internal/helpers/webpack-module-path.ts
View file @
74b09dd0
...
@@ -18,18 +18,15 @@ export function isWebpackInternalResource(file: string) {
...
@@ -18,18 +18,15 @@ export function isWebpackInternalResource(file: string) {
/**
/**
* Format the webpack internal id to original file path
* Format the webpack internal id to original file path
*
* webpack-internal:///./src/hello.tsx => ./src/hello.tsx
* webpack-internal:///./src/hello.tsx => ./src/hello.tsx
* rsc://React/Server/webpack-internal:///(rsc)/./src/hello.tsx?42 => ./src/hello.tsx
* rsc://React/Server/webpack-internal:///(rsc)/./src/hello.tsx?42 => ./src/hello.tsx
* rsc://React/Server/webpack:///app/indirection.tsx?14cb?0 => app/indirection.tsx
* rsc://React/Server/webpack:///app/indirection.tsx?14cb?0 => app/indirection.tsx
* webpack://_N_E/./src/hello.tsx => ./src/hello.tsx
* webpack://_N_E/./src/hello.tsx => ./src/hello.tsx
* webpack://./src/hello.tsx => ./src/hello.tsx
* webpack://./src/hello.tsx => ./src/hello.tsx
* webpack:///./src/hello.tsx => ./src/hello.tsx
* webpack:///./src/hello.tsx => ./src/hello.tsx
*
* <anonymous> => ''
*/
*/
export
function
formatFrameSourceFile
(
file
:
string
)
{
export
function
formatFrameSourceFile
(
file
:
string
)
{
if
(
file
===
'<anonymous>'
)
return
''
for
(
const
regex
of
replacementRegExes
)
{
for
(
const
regex
of
replacementRegExes
)
{
file
=
file
.
replace
(
regex
,
''
)
file
=
file
.
replace
(
regex
,
''
)
}
}
...
...
test/development/acceptance/ReactRefreshLogBox.test.ts
View file @
74b09dd0
...
@@ -3,6 +3,7 @@ import { createSandbox } from 'development-sandbox'
...
@@ -3,6 +3,7 @@ import { createSandbox } from 'development-sandbox'
import
{
FileRef
,
nextTestSetup
}
from
'e2e-utils'
import
{
FileRef
,
nextTestSetup
}
from
'e2e-utils'
import
{
import
{
describeVariants
as
describe
,
describeVariants
as
describe
,
getRedboxCallStack
,
toggleCollapseCallStackFrames
,
toggleCollapseCallStackFrames
,
}
from
'next-test-utils'
}
from
'next-test-utils'
import
path
from
'path'
import
path
from
'path'
...
@@ -770,36 +771,25 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
...
@@ -770,36 +771,25 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
expect
(
callStackFrames
.
length
).
toBeGreaterThan
(
9
)
expect
(
callStackFrames
.
length
).
toBeGreaterThan
(
9
)
})
})
test
(
'should
hide unrelated frames in stack trace with unknown anonymous calls
'
,
async
()
=>
{
test
(
'should
show anonymous frames in stack trace
'
,
async
()
=>
{
await
using
sandbox
=
await
createSandbox
(
await
using
sandbox
=
await
createSandbox
(
next
,
next
,
new
Map
([
new
Map
([
[
[
'pages/index.js'
,
'pages/index.js'
,
// TODO: repro stringify (<anonymous>)
outdent
`
outdent
`
export default function Page() {
export default function Page() {
const e = new Error("Client error!");
[1, 2, 3].map(() => {
e.stack += \`
throw new Error("anonymous error!");
at stringify (<anonymous>)
})
at <unknown> (<anonymous>)
}`
,
at foo (bar:1:1)\`;
throw e;
}
`
,
],
],
])
])
)
)
const
{
session
,
browser
}
=
sandbox
const
{
session
,
browser
}
=
sandbox
await
session
.
assertHasRedbox
()
await
session
.
assertHasRedbox
()
await
toggleCollapseCallStackFrames
(
browser
)
const
texts
=
await
getRedboxCallStack
(
browser
)
let
callStackFrames
=
await
browser
.
elementsByCss
(
expect
(
texts
).
toMatchSnapshot
()
'[data-nextjs-call-stack-frame]'
)
let
texts
=
await
Promise
.
all
(
callStackFrames
.
map
((
f
)
=>
f
.
innerText
()))
expect
(
texts
).
not
.
toContain
(
'stringify
\
n<anonymous>'
)
expect
(
texts
).
not
.
toContain
(
'<unknown>
\
n<anonymous>'
)
expect
(
texts
).
toContain
(
'foo
\
nbar (1:1)'
)
})
})
test
(
'should hide unrelated frames in stack trace with node:internal calls'
,
async
()
=>
{
test
(
'should hide unrelated frames in stack trace with node:internal calls'
,
async
()
=>
{
...
...
test/development/acceptance/__snapshots__/ReactRefreshLogBox.test.ts.snap
View file @
74b09dd0
...
@@ -54,6 +54,13 @@ exports[`ReactRefreshLogBox default module init error not shown 1`] = `
...
@@ -54,6 +54,13 @@ exports[`ReactRefreshLogBox default module init error not shown 1`] = `
6 | return <h1>Default Export</h1>;"
6 | return <h1>Default Export</h1>;"
`;
`;
exports[`ReactRefreshLogBox default should show anonymous frames in stack trace 1`] = `
"Array.map
<anonymous> (0:0)
map
pages/index.js (2:13)"
`;
exports[`ReactRefreshLogBox default should strip whitespace correctly with newline 1`] = `
exports[`ReactRefreshLogBox default should strip whitespace correctly with newline 1`] = `
"index.js (8:27) @ onClick
"index.js (8:27) @ onClick
...
@@ -118,6 +125,13 @@ exports[`ReactRefreshLogBox turbo module init error not shown 1`] = `
...
@@ -118,6 +125,13 @@ exports[`ReactRefreshLogBox turbo module init error not shown 1`] = `
6 | return <h1>Default Export</h1>;"
6 | return <h1>Default Export</h1>;"
`;
`;
exports[`ReactRefreshLogBox turbo should show anonymous frames in stack trace 1`] = `
"Array.map
<anonymous> (0:0)
Page
pages/index.js (2:13)"
`;
exports[`ReactRefreshLogBox turbo should strip whitespace correctly with newline 1`] = `
exports[`ReactRefreshLogBox turbo should strip whitespace correctly with newline 1`] = `
"index.js (8:27) @ onClick
"index.js (8:27) @ onClick
...
...
test/development/app-dir/capture-console-error-owner-stack/capture-console-error-owner-stack.test.ts
View file @
74b09dd0
...
@@ -42,7 +42,9 @@ describe('app-dir - capture-console-error-owner-stack', () => {
...
@@ -42,7 +42,9 @@ describe('app-dir - capture-console-error-owner-stack', () => {
if
(
process
.
env
.
TURBOPACK
)
{
if
(
process
.
env
.
TURBOPACK
)
{
expect
(
result
).
toMatchInlineSnapshot
(
`
expect
(
result
).
toMatchInlineSnapshot
(
`
{
{
"callStacks": "Page
"callStacks": "button
<anonymous> (0:0)
Page
app/browser/event/page.js (5:5)",
app/browser/event/page.js (5:5)",
"count": 1,
"count": 1,
"description": "trigger an console <error>",
"description": "trigger an console <error>",
...
@@ -62,6 +64,8 @@ describe('app-dir - capture-console-error-owner-stack', () => {
...
@@ -62,6 +64,8 @@ describe('app-dir - capture-console-error-owner-stack', () => {
expect
(
result
).
toMatchInlineSnapshot
(
`
expect
(
result
).
toMatchInlineSnapshot
(
`
{
{
"callStacks": "button
"callStacks": "button
<anonymous> (0:0)
button
app/browser/event/page.js (5:6)",
app/browser/event/page.js (5:6)",
"count": 1,
"count": 1,
"description": "trigger an console <error>",
"description": "trigger an console <error>",
...
@@ -274,7 +278,10 @@ describe('app-dir - capture-console-error-owner-stack', () => {
...
@@ -274,7 +278,10 @@ describe('app-dir - capture-console-error-owner-stack', () => {
if
(
process
.
env
.
TURBOPACK
)
{
if
(
process
.
env
.
TURBOPACK
)
{
expect
(
result
).
toMatchInlineSnapshot
(
`
expect
(
result
).
toMatchInlineSnapshot
(
`
{
{
"callStacks": "",
"callStacks": "JSON.parse
<anonymous> (0:0)
Page
<anonymous> (0:0)",
"count": 1,
"count": 1,
"description": "[ Server ] Error: boom",
"description": "[ Server ] Error: boom",
"source": "app/rsc/page.js (2:17) @ Page
"source": "app/rsc/page.js (2:17) @ Page
...
@@ -291,7 +298,10 @@ describe('app-dir - capture-console-error-owner-stack', () => {
...
@@ -291,7 +298,10 @@ describe('app-dir - capture-console-error-owner-stack', () => {
}
else
{
}
else
{
expect
(
result
).
toMatchInlineSnapshot
(
`
expect
(
result
).
toMatchInlineSnapshot
(
`
{
{
"callStacks": "",
"callStacks": "JSON.parse
<anonymous> (0:0)
Page
<anonymous> (0:0)",
"count": 1,
"count": 1,
"description": "[ Server ] Error: boom",
"description": "[ Server ] Error: boom",
"source": "app/rsc/page.js (2:17) @ Page
"source": "app/rsc/page.js (2:17) @ Page
...
...
test/development/app-dir/capture-console-error/capture-console-error.test.ts
View file @
74b09dd0
...
@@ -280,7 +280,8 @@ describe('app-dir - capture-console-error', () => {
...
@@ -280,7 +280,8 @@ describe('app-dir - capture-console-error', () => {
if
(
process
.
env
.
TURBOPACK
)
{
if
(
process
.
env
.
TURBOPACK
)
{
expect
(
result
).
toMatchInlineSnapshot
(
`
expect
(
result
).
toMatchInlineSnapshot
(
`
{
{
"callStacks": "",
"callStacks": "JSON.parse
<anonymous> (0:0)",
"count": 1,
"count": 1,
"description": "[ Server ] Error: boom",
"description": "[ Server ] Error: boom",
"source": "app/rsc/page.js (2:17) @ Page
"source": "app/rsc/page.js (2:17) @ Page
...
@@ -297,7 +298,8 @@ describe('app-dir - capture-console-error', () => {
...
@@ -297,7 +298,8 @@ describe('app-dir - capture-console-error', () => {
}
else
{
}
else
{
expect
(
result
).
toMatchInlineSnapshot
(
`
expect
(
result
).
toMatchInlineSnapshot
(
`
{
{
"callStacks": "",
"callStacks": "JSON.parse
<anonymous> (0:0)",
"count": 1,
"count": 1,
"description": "[ Server ] Error: boom",
"description": "[ Server ] Error: boom",
"source": "app/rsc/page.js (2:17) @ Page
"source": "app/rsc/page.js (2:17) @ Page
...
...
test/development/app-dir/dynamic-error-trace/index.test.ts
View file @
74b09dd0
...
@@ -36,9 +36,15 @@ describe('app dir - dynamic error trace', () => {
...
@@ -36,9 +36,15 @@ describe('app dir - dynamic error trace', () => {
.
join
(
'
\
n'
)
.
join
(
'
\
n'
)
// TODO: Show useful stack
// TODO: Show useful stack
expect
(
normalizeStackTrace
(
stackFramesContent
)).
toMatchInlineSnapshot
(
const
normalizedStack
=
normalizeStackTrace
(
stackFramesContent
)
isReactExperimental
?
`""`
:
`""`
if
(
isReactExperimental
)
{
)
expect
(
normalizedStack
).
toMatchInlineSnapshot
(
`
"Array.map
<anonymous>"
`
)
}
else
{
expect
(
normalizedStack
).
toMatchInlineSnapshot
(
`""`
)
}
const
codeframe
=
await
getRedboxSource
(
browser
)
const
codeframe
=
await
getRedboxSource
(
browser
)
expect
(
codeframe
).
toEqual
(
expect
(
codeframe
).
toEqual
(
...
...
test/development/app-dir/owner-stack-react-missing-key-prop/owner-stack-react-missing-key-prop.test.ts
View file @
74b09dd0
...
@@ -25,37 +25,39 @@ const isOwnerStackEnabled =
...
@@ -25,37 +25,39 @@ const isOwnerStackEnabled =
const
source
=
await
getRedboxSource
(
browser
)
const
source
=
await
getRedboxSource
(
browser
)
if
(
process
.
env
.
TURBOPACK
)
{
if
(
process
.
env
.
TURBOPACK
)
{
expect
(
stackFramesContent
).
toMatchInlineSnapshot
(
expect
(
stackFramesContent
).
toMatchInlineSnapshot
(
`
`"at Page (app/rsc/page.tsx (6:13))"`
"at span ()
)
at Page (app/rsc/page.tsx (6:13))"
`
)
expect
(
source
).
toMatchInlineSnapshot
(
`
expect
(
source
).
toMatchInlineSnapshot
(
`
"app/rsc/page.tsx (7:10) @ <anonymous>
"app/rsc/page.tsx (7:10) @ <anonymous>
5 | <div>
5 | <div>
6 | {list.map((item, index) => (
6 | {list.map((item, index) => (
> 7 | <span>{item}</span>
> 7 | <span>{item}</span>
| ^
| ^
8 | ))}
8 | ))}
9 | </div>
9 | </div>
10 | )"
10 | )"
`
)
`
)
}
else
{
}
else
{
// FIXME: the owner stack method names should be `Page` instead of `map`
// FIXME: the owner stack method names should be `Page` instead of `map`
expect
(
stackFramesContent
).
toMatchInlineSnapshot
(
expect
(
stackFramesContent
).
toMatchInlineSnapshot
(
`
`"at map (app/rsc/page.tsx (6:13))"`
"at span ()
)
at map (app/rsc/page.tsx (6:13))"
`
)
// FIXME: the methodName should be `@ <anonymous>` instead of `@ span`
// FIXME: the methodName should be `@ <anonymous>` instead of `@ span`
expect
(
source
).
toMatchInlineSnapshot
(
`
expect
(
source
).
toMatchInlineSnapshot
(
`
"app/rsc/page.tsx (7:10) @ span
"app/rsc/page.tsx (7:10) @ span
5 | <div>
5 | <div>
6 | {list.map((item, index) => (
6 | {list.map((item, index) => (
> 7 | <span>{item}</span>
> 7 | <span>{item}</span>
| ^
| ^
8 | ))}
8 | ))}
9 | </div>
9 | </div>
10 | )"
10 | )"
`
)
`
)
}
}
})
})
...
@@ -66,37 +68,41 @@ const isOwnerStackEnabled =
...
@@ -66,37 +68,41 @@ const isOwnerStackEnabled =
const
stackFramesContent
=
await
getStackFramesContent
(
browser
)
const
stackFramesContent
=
await
getStackFramesContent
(
browser
)
const
source
=
await
getRedboxSource
(
browser
)
const
source
=
await
getRedboxSource
(
browser
)
if
(
process
.
env
.
TURBOPACK
)
{
if
(
process
.
env
.
TURBOPACK
)
{
expect
(
stackFramesContent
).
toMatchInlineSnapshot
(
expect
(
stackFramesContent
).
toMatchInlineSnapshot
(
`
`"at Page (app/ssr/page.tsx (8:13))"`
"at p ()
)
at Array.map ()
at Page (app/ssr/page.tsx (8:13))"
`
)
expect
(
source
).
toMatchInlineSnapshot
(
`
expect
(
source
).
toMatchInlineSnapshot
(
`
"app/ssr/page.tsx (9:9) @ <unknown>
"app/ssr/page.tsx (9:9) @ <unknown>
7 | <div>
7 | <div>
8 | {list.map((item, index) => (
8 | {list.map((item, index) => (
> 9 | <p>{item}</p>
> 9 | <p>{item}</p>
| ^
| ^
10 | ))}
10 | ))}
11 | </div>
11 | </div>
12 | )"
12 | )"
`
)
`
)
}
else
{
}
else
{
// FIXME: the owner stack method names should be `Page` instead of `map`
// FIXME: the owner stack method names should be `Page` instead of `map`
expect
(
stackFramesContent
).
toMatchInlineSnapshot
(
expect
(
stackFramesContent
).
toMatchInlineSnapshot
(
`
`"at map (app/ssr/page.tsx (8:13))"`
"at p ()
)
at Array.map ()
at map (app/ssr/page.tsx (8:13))"
`
)
// FIXME: the methodName should be `@ <unknown>` instead of `@ p`
// FIXME: the methodName should be `@ <unknown>` instead of `@ p`
expect
(
source
).
toMatchInlineSnapshot
(
`
expect
(
source
).
toMatchInlineSnapshot
(
`
"app/ssr/page.tsx (9:10) @ p
"app/ssr/page.tsx (9:10) @ p
7 | <div>
7 | <div>
8 | {list.map((item, index) => (
8 | {list.map((item, index) => (
> 9 | <p>{item}</p>
> 9 | <p>{item}</p>
| ^
| ^
10 | ))}
10 | ))}
11 | </div>
11 | </div>
12 | )"
12 | )"
`
)
`
)
}
}
})
})
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment