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
286c14d0
Unverified
Commit
286c14d0
authored
Jan 06, 2025
by
Jiachi Liu
Committed by
GitHub
Jan 06, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: add node internals stack frames to ignored list (#73698)
parent
4c5fa1dc
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
44 deletions
+58
-44
stack-frame.ts
...ponents/react-dev-overlay/internal/helpers/stack-frame.ts
+1
-5
middleware-turbopack.ts
...mponents/react-dev-overlay/server/middleware-turbopack.ts
+26
-3
middleware-webpack.ts
...components/react-dev-overlay/server/middleware-webpack.ts
+2
-1
ReactRefreshLogBox.test.ts
test/development/acceptance/ReactRefreshLogBox.test.ts
+29
-21
ReactRefreshLogBox.test.ts.snap
.../acceptance/__snapshots__/ReactRefreshLogBox.test.ts.snap
+0
-14
No files found.
packages/next/src/client/components/react-dev-overlay/internal/helpers/stack-frame.ts
View file @
286c14d0
...
@@ -58,11 +58,7 @@ function getOriginalStackFrame(
...
@@ -58,11 +58,7 @@ function getOriginalStackFrame(
}
}
// TODO: merge this section into ignoredList handling
// TODO: merge this section into ignoredList handling
if
(
if
(
source
.
file
===
'file://'
||
source
.
file
?.
match
(
/https
?
:
\/\/
/
))
{
source
.
file
===
'file://'
||
source
.
file
?.
match
(
/^node:/
)
||
source
.
file
?.
match
(
/https
?
:
\/\/
/
)
)
{
return
Promise
.
resolve
({
return
Promise
.
resolve
({
error
:
false
,
error
:
false
,
reason
:
null
,
reason
:
null
,
...
...
packages/next/src/client/components/react-dev-overlay/server/middleware-turbopack.ts
View file @
286c14d0
...
@@ -24,7 +24,8 @@ function shouldIgnorePath(modulePath: string): boolean {
...
@@ -24,7 +24,8 @@ function shouldIgnorePath(modulePath: string): boolean {
return
(
return
(
modulePath
.
includes
(
'node_modules'
)
||
modulePath
.
includes
(
'node_modules'
)
||
// Only relevant for when Next.js is symlinked e.g. in the Next.js monorepo
// Only relevant for when Next.js is symlinked e.g. in the Next.js monorepo
modulePath
.
includes
(
'next/dist'
)
modulePath
.
includes
(
'next/dist'
)
||
modulePath
.
startsWith
(
'node:'
)
)
)
}
}
...
@@ -39,8 +40,25 @@ export async function batchedTraceSource(
...
@@ -39,8 +40,25 @@ export async function batchedTraceSource(
?
// TODO(veil): Why are the frames sent encoded?
?
// TODO(veil): Why are the frames sent encoded?
decodeURIComponent
(
frame
.
file
)
decodeURIComponent
(
frame
.
file
)
:
undefined
:
undefined
if
(
!
file
)
return
if
(
!
file
)
return
// For node internals they cannot traced the actual source code with project.traceSource,
// we need an early return to indicate it's ignored to avoid the unknown scheme error from `project.traceSource`.
if
(
file
.
startsWith
(
'node:'
))
{
return
{
frame
:
{
file
,
lineNumber
:
frame
.
line
??
0
,
column
:
frame
.
column
??
0
,
methodName
:
frame
.
methodName
??
'<unknown>'
,
ignored
:
true
,
arguments
:
[],
},
source
:
null
,
}
}
const
currentDirectoryFileUrl
=
pathToFileURL
(
process
.
cwd
()).
href
const
currentDirectoryFileUrl
=
pathToFileURL
(
process
.
cwd
()).
href
const
sourceFrame
=
await
project
.
traceSource
(
frame
,
currentDirectoryFileUrl
)
const
sourceFrame
=
await
project
.
traceSource
(
frame
,
currentDirectoryFileUrl
)
...
@@ -51,7 +69,7 @@ export async function batchedTraceSource(
...
@@ -51,7 +69,7 @@ export async function batchedTraceSource(
lineNumber
:
frame
.
line
??
0
,
lineNumber
:
frame
.
line
??
0
,
column
:
frame
.
column
??
0
,
column
:
frame
.
column
??
0
,
methodName
:
frame
.
methodName
??
'<unknown>'
,
methodName
:
frame
.
methodName
??
'<unknown>'
,
ignored
:
shouldIgnorePath
(
f
rame
.
f
ile
),
ignored
:
shouldIgnorePath
(
file
),
arguments
:
[],
arguments
:
[],
},
},
source
:
null
,
source
:
null
,
...
@@ -60,6 +78,7 @@ export async function batchedTraceSource(
...
@@ -60,6 +78,7 @@ export async function batchedTraceSource(
let
source
=
null
let
source
=
null
const
originalFile
=
sourceFrame
.
originalFile
const
originalFile
=
sourceFrame
.
originalFile
// Don't look up source for node_modules or internals. These can often be large bundled files.
// Don't look up source for node_modules or internals. These can often be large bundled files.
const
ignored
=
const
ignored
=
shouldIgnorePath
(
originalFile
??
sourceFrame
.
file
)
||
shouldIgnorePath
(
originalFile
??
sourceFrame
.
file
)
||
...
@@ -226,7 +245,11 @@ async function nativeTraceSource(
...
@@ -226,7 +245,11 @@ async function nativeTraceSource(
const
sourceIndex
=
applicableSourceMap
.
sources
.
indexOf
(
const
sourceIndex
=
applicableSourceMap
.
sources
.
indexOf
(
originalPosition
.
source
!
originalPosition
.
source
!
)
)
ignored
=
applicableSourceMap
.
ignoreList
?.
includes
(
sourceIndex
)
??
false
ignored
=
applicableSourceMap
.
ignoreList
?.
includes
(
sourceIndex
)
??
// When sourcemap is not available, fallback to checking `frame.file`.
// e.g. In pages router, nextjs server code is not bundled into the page.
shouldIgnorePath
(
frame
.
file
)
}
}
const
originalStackFrame
:
IgnorableStackFrame
=
{
const
originalStackFrame
:
IgnorableStackFrame
=
{
...
...
packages/next/src/client/components/react-dev-overlay/server/middleware-webpack.ts
View file @
286c14d0
...
@@ -30,7 +30,8 @@ function shouldIgnorePath(modulePath: string): boolean {
...
@@ -30,7 +30,8 @@ function shouldIgnorePath(modulePath: string): boolean {
return
(
return
(
modulePath
.
includes
(
'node_modules'
)
||
modulePath
.
includes
(
'node_modules'
)
||
// Only relevant for when Next.js is symlinked e.g. in the Next.js monorepo
// Only relevant for when Next.js is symlinked e.g. in the Next.js monorepo
modulePath
.
includes
(
'next/dist'
)
modulePath
.
includes
(
'next/dist'
)
||
modulePath
.
startsWith
(
'node:'
)
)
)
}
}
...
...
test/development/acceptance/ReactRefreshLogBox.test.ts
View file @
286c14d0
...
@@ -3,7 +3,7 @@ import { createSandbox } from 'development-sandbox'
...
@@ -3,7 +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
,
get
RedboxCallStack
,
get
StackFramesContent
,
toggleCollapseCallStackFrames
,
toggleCollapseCallStackFrames
,
}
from
'next-test-utils'
}
from
'next-test-utils'
import
path
from
'path'
import
path
from
'path'
...
@@ -771,7 +771,8 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
...
@@ -771,7 +771,8 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
expect
(
callStackFrames
.
length
).
toBeGreaterThan
(
9
)
expect
(
callStackFrames
.
length
).
toBeGreaterThan
(
9
)
})
})
test
(
'should show anonymous frames in stack trace'
,
async
()
=>
{
// TODO: hide the anonymous frames between 2 ignored frames
test
(
'should show anonymous frames from stack trace'
,
async
()
=>
{
await
using
sandbox
=
await
createSandbox
(
await
using
sandbox
=
await
createSandbox
(
next
,
next
,
new
Map
([
new
Map
([
...
@@ -786,42 +787,49 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
...
@@ -786,42 +787,49 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
],
],
])
])
)
)
const
{
session
,
browser
}
=
sandbox
const
{
session
,
browser
}
=
sandbox
await
session
.
assertHasRedbox
()
await
session
.
assertHasRedbox
()
const
texts
=
await
getRedboxCallStack
(
browser
)
expect
(
texts
).
toMatchSnapshot
()
const
stack
=
await
getStackFramesContent
(
browser
)
expect
(
stack
).
toMatchInlineSnapshot
(
`
"at Array.map ()
at Page (pages/index.js (2:13))"
`
)
})
})
test
(
'should
hide unrelated frames in stack trace with node:internal calls
'
,
async
()
=>
{
test
(
'should
collapse nodejs internal stack frames from 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'
,
// Node.js will throw an error about the invalid URL since it happens server-side
outdent
`
outdent
`
export default function Page() {}
export default function Page() {}
function createURL() {
new URL("/", "invalid")
}
export function getServerSideProps() {
export function getServerSideProps() {
new URL("/", "invalid");
createURL()
return { props: {} };
return { props: {} }
}`
,
}`
,
],
],
])
])
)
)
const
{
session
,
browser
}
=
sandbox
const
{
session
,
browser
}
=
sandbox
await
session
.
assertHasRedbox
()
await
session
.
assertHasRedbox
()
// Should still show the errored line in source code
const
stack
=
await
getStackFramesContent
(
browser
)
const
source
=
await
session
.
getRedboxSource
()
expect
(
stack
).
toMatchInlineSnapshot
(
expect
(
source
).
toContain
(
'pages/index.js'
)
`"at getServerSideProps (pages/index.js (8:3))"`
expect
(
source
).
toContain
(
`new URL("/", "invalid")`
)
const
callStackFrames
=
await
browser
.
elementsByCss
(
'[data-nextjs-call-stack-frame]'
)
)
const
texts
=
await
Promise
.
all
(
callStackFrames
.
map
((
f
)
=>
f
.
innerText
()))
expect
(
texts
.
filter
((
t
)
=>
t
.
includes
(
'node:internal'
))).
toHaveLength
(
0
)
await
toggleCollapseCallStackFrames
(
browser
)
const
stackCollapsed
=
await
getStackFramesContent
(
browser
)
expect
(
stackCollapsed
).
toContain
(
'at new URL ()'
)
})
})
})
})
test/development/acceptance/__snapshots__/ReactRefreshLogBox.test.ts.snap
View file @
286c14d0
...
@@ -54,13 +54,6 @@ exports[`ReactRefreshLogBox default module init error not shown 1`] = `
...
@@ -54,13 +54,6 @@ 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)
Page
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
...
@@ -125,13 +118,6 @@ exports[`ReactRefreshLogBox turbo module init error not shown 1`] = `
...
@@ -125,13 +118,6 @@ 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
...
...
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