-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Component Stack doesn't appear in Sentry dashboard. #7293
Comments
I did some investigation on this. Generally, we can only pick up the component stack in dev mode because react will only log the hydration warning containing the component stack in dev mode. This is what the Next.js dev overlay does to display these errors. Next.js patches We opened an issue with react (facebook/react#26224) hoping that we can somehow make the component stack available on hydration errors so that we can collect the stack trace even in react production mode. We'll probably not tackle this right now, as it would only affect Next.js dev mode which is displayed in the overlay. However, we might think about contributing upstream to attach the component stack to hydration errors. |
@meotimdihia here's a quick hack to monkeypatch NextJS if you want this to be set on prod Sentry events (but warning, it is very much a HACK, could break at any time) // sentry.client.config.js
import * as client from "react-dom/client";
const oldClientHydrateRoot = client.hydrateRoot;
client.hydrateRoot = new Proxy(oldClientHydrateRoot, {
apply: (wrappingTarget, thisArg, args) => {
const oldOnRecoverableError = args[2].onRecoverableError;
args[2].onRecoverableError = new Proxy(oldOnRecoverableError, {
apply: (inner_wrappingTarget, inner_thisArg, inner_args) => {
const error = inner_args[0];
const errorInfo = inner_args[1];
const errorBoundaryError = new Error(error.message);
errorBoundaryError.name = `React ErrorBoundary ${errorBoundaryError.name}`;
errorBoundaryError.stack = errorInfo.componentStack;
// Using the `LinkedErrors` integration to link the errors together.
error.cause = errorBoundaryError;
Sentry.captureException(error, { contexts: { react: { componentStack } } });
});
return wrappingTarget.apply(thisArg, args);
},
});
// ...
Sentry.init({
... |
Going to close this for now since we are blocked by next.js exposing this for us - feel free to upvote/comment on the GH discussion to get the attention of the Next.js team! vercel/next.js#36641 |
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using? If you use the CDN bundles, please specify the exact bundle (e.g.
bundle.tracing.min.js
) in your SDK setup.@sentry/nextjs
SDK Version
7.39.0
Framework Version
React 18+
Link to Sentry event
No response
SDK Setup
No response
Steps to Reproduce
Problem Statement
Next.js recently added Component Stack for the errors:
This is an error that I can't produce on the client. It just reports once and disappears
Related to these issues:
validateDOMNesting
Hydration failed facebook/react#24519 (comment)validateDOMNesting
Hydration failed facebook/react#24519 (comment)Expected Result
I could see the Component Stack.
Actual Result
The text was updated successfully, but these errors were encountered: