-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
feat: add component stack to recoverable error #50943
Conversation
Attaches any component stack from error info to the error object on a recoverable error. This will help understanding hydration mismatch errors in production logs.
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
: (error: any) => { | ||
window.console.error(error) | ||
: (error: any, errorInfo: ErrorInfo) => { | ||
window.console.error(error, errorInfo) |
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.
Let me know whether we feel logging this to console is helpful here for use cases in production where reportError
is not available. Otherwise we can reduce this PR down to only attaching err._componentStack
above.
Stats from current PRDefault BuildGeneral
Client Bundles (main, webpack)
Legacy Client Bundles (polyfills)
Client Pages
Client Build Manifests
Rendered Page Sizes
Edge SSR bundle Size
Middleware size
Next Runtimes
|
Checking the merge conflicts, it appears that this or something similar was later added via #65058 (see https://github.com/vercel/next.js/pull/65058/files#diff-40961531401a39b81aba34f10e895430cdd657ee928057817321fb857a068fd7)! 🎉 That's good news! I'll close this PR then. Thanks! |
What?
Attaches any component stack from error info to the error object on a recoverable error.
Why?
Hopefully this will help understanding hydration mismatch errors in production logs - not just in development, which we understand is already supported. I have confirmed that component stack is provided with error info in production builds. Apps can implement a custom
window.onerror
orwindow
error
event listener and grab the component stack from the error object to submit to their logging systems.How?
A simple code change to extend the error object with a
_componentStack
property, aligning with what is already done in development with@next/react-dev-overlay
. Open to other property names if preferred.Do we feel there is any risk in adding this property to the error object?
Is there a recommended way to unit test this, if needed?
Let me know if it would be necessary or useful to add documentation, and to where.
Related to #47542 and #36641 (comment).