Description
Hey folks! We at Sentry build error/performance monitoring SDKs and wanted to reach out to see if we could improve the state of hydration errors and make them more actionable. Specifically, we want to look at the stacktraces of hydration errors when you are using production react bundles.
Since React 18 has been getting more adoption, many of our users using React SSR apps have been getting flooded with hydration errors, like listed below:
'https://reactjs.org/docs/error-decoder.html?invariant=422', // There was an error while hydrating this Suspense boundary. Switched to client rendering.
'https://reactjs.org/docs/error-decoder.html?invariant=423', // There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root...
'https://reactjs.org/docs/error-decoder.html?invariant=425' // Text content does not match server-rendered HTML...
When we discussed this with the community, many users simply wanted to just filter these errors because they were not actionable.
Looking at the implementation in the codebase a simple string error is thrown:
and because of how it is generated the stack trace is often not detailed enough to give users insights about what components/functions were problematic.
For example, here's a stacktrace I generated from a stock Next.js application with one of these hydration errors:
https://sentry-test.sentry.io/share/issue/b70ea591bbfc4728b33da495148ac9cd/
Error: There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.
at Vk(./node_modules/react-dom/cjs/react-dom.production.min.js:280:383)
at 4448/oF/<(./node_modules/react-dom/cjs/react-dom.production.min.js:280:319)
at Jk(./node_modules/react-dom/cjs/react-dom.production.min.js:280:319)
at Ok(./node_modules/react-dom/cjs/react-dom.production.min.js:271:86)
at Hk(./node_modules/react-dom/cjs/react-dom.production.min.js:268:399)
at J(./node_modules/scheduler/cjs/scheduler.production.min.js:13:197)
at R(./node_modules/scheduler/cjs/scheduler.production.min.js:14:126)
As you can see the frames all come from react-dom
internals, which means users have no way to start investigating where to look beyond the URL of the page.
In the end we've decided to filter these out from default from sentry: getsentry/sentry#45038, but we recognize this is not an ideal solution. Hydration errors are things people should fix, and we want to make it easier for people to fix them!
So with that in mind, are there ways we could make this easier for users? Could we attach a componentStack
like we do with error boundaries for these errors? Could we point users to the element that was causing this issue? Any and all ideas/feeback greatly appreciated.