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
613facf8
Commit
613facf8
authored
Nov 24, 2025
by
Jiachi Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve forward logs stack display
parent
7e093afb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
6 deletions
+15
-6
forward-logs.ts
...ages/next/src/next-devtools/userspace/app/forward-logs.ts
+12
-5
page.tsx
...ment/mcp-server/fixtures/log-file-app/app/client/page.tsx
+3
-1
No files found.
packages/next/src/next-devtools/userspace/app/forward-logs.ts
View file @
613facf8
...
...
@@ -336,7 +336,11 @@ const createErrorArg = (error: Error) => {
}
}
const
createLogEntry
=
(
level
:
LogMethod
,
args
:
any
[])
=>
{
const
createLogEntry
=
(
level
:
LogMethod
,
args
:
any
[],
capturedStack
?:
string
|
null
)
=>
{
// Always log to client file logger with args (formatting done inside log method)
clientFileLogger
.
log
(
level
,
args
)
...
...
@@ -345,9 +349,9 @@ const createLogEntry = (level: LogMethod, args: any[]) => {
return
}
//
do not abstract this, it implicitly relies on which functions call it. forcing the inlined implementation makes you think about callers
//
error capture stack trace maybe
const
stack
=
stackWithOwners
(
new
Error
())
//
Prefer a stack captured at the original console.* callsite (from the patched
//
console wrapper) if one was provided; otherwise, fall back to capturing here.
const
stack
=
capturedStack
??
stackWithOwners
(
new
Error
())
const
stackLines
=
stack
?.
split
(
'
\
n'
)
const
cleanStack
=
stackLines
?.
slice
(
3
).
join
(
'
\
n'
)
// this is probably ignored anyways
const
entry
:
ConsoleEntry
<
unknown
>
=
{
...
...
@@ -561,13 +565,16 @@ export const initializeDebugLogForwarding = (router: 'app' | 'pages'): void => {
try
{
methods
.
forEach
((
method
)
=>
patchConsoleMethod
(
method
,
(
_
,
...
args
)
=>
{
// Capture the stack as close as possible to the original console.* call.
const
stack
=
stackWithOwners
(
new
Error
())
if
(
isHMR
(
args
))
{
return
}
if
(
isReactServerReplayedLog
(
args
))
{
return
}
createLogEntry
(
method
,
args
)
createLogEntry
(
method
,
args
,
stack
)
})
)
}
catch
{}
...
...
test/development/mcp-server/fixtures/log-file-app/app/client/page.tsx
View file @
613facf8
...
...
@@ -26,7 +26,9 @@ export default function ClientPage() {
console
.
warn
(
'Client: This is a warning message from client component'
)
},
[])
console
.
error
(
'globalThis'
,
globalThis
)
if
(
typeof
window
!==
'undefined'
)
{
console
.
error
(
'window'
,
window
)
}
return
<
p
>
client page with logging
</
p
>
}
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