-
Notifications
You must be signed in to change notification settings - Fork 30.3k
Fix console.trace including unexpected lines #88319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: canary
Are you sure you want to change the base?
Fix console.trace including unexpected lines #88319
Conversation
Failing test suitesCommit: 4e97364 | About building and testing Next.js
Expand output● interception-dynamic-segment › should work when interception route is paired with a dynamic segment ● interception-dynamic-segment › should intercept consistently with back/forward navigation ● interception-dynamic-segment › should intercept multiple times from root |
| if (methodName === 'trace' && traceStack !== undefined) { | ||
| const label = args.length > 0 ? `Trace: ${args.join(' ')}` : 'Trace' | ||
| const traceOutput = `${label}\n${traceStack}` | ||
| // Use console.log with the dimmed trace output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // For console.trace, output the label + clean stack using console.log | ||
| // This goes through the wrapper chain for proper file logging | ||
| const label = args.length > 0 ? `Trace: ${args.join(' ')}` : 'Trace' | ||
| return console.log(`${label}\n${traceStack}`) as ReturnType<F> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stats from current PR✅ No significant changes detected📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles: **430 kB** → **430 kB** ✅ -4 B82 files with content-based hashes (individual files not comparable between builds) Server Middleware
Build DetailsBuild Manifests
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
|

What?
Fixed
console.traceto output a clean stack trace that shows the actual call site and parent frames, instead of polluting the output with internal Next.js console patching frames.Why?
Before this fix, calling
console.trace('Test')in a Next.js project would output:The internal wrapper frames from
console-file,console-exit, andconsole-dim.externalwere polluting the stack trace, making it difficult to debug.How?
In
console-dim.external.tsx(the outermost wrapper):getCleanStackTrace()function that captures the stack trace early and filters out any frames containing/node-environment-extensions/console.tracebefore entering the wrapper chainconsole.log(which still goes through the wrapper chain for proper file logging) instead of delegating to the originalconsole.traceAfter this fix:
Test Plan
Added unit test
should output console.trace with a clean stack trace without internal wrapper framestoconsole-dim.external.test.tsthat verifies:/node-environment-extensions/frames