Skip to content
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

Catch hydration errors and link to Hydrogen issue #1032

Merged
merged 2 commits into from Apr 5, 2022

Conversation

jplhomer
Copy link
Contributor

@jplhomer jplhomer commented Apr 3, 2022

Description

We see quite a few hydration errors right now related to Suspense and server components: #920

Screen Shot 2022-04-03 at 11 19 04 AM

This is fine, because the client rendering of the server components response works just fine. However, it distracts developers and makes them think something is wrong with their application.

This PR leverages the newonRecoverableError hook to catch hydration errors. In development, we print out a message explaining that it's due to experimental bugs with a link to the Hydrogen issue. In production, nothing is printed, and the user isn't the wiser that any hydration error happened at all.

In development, the hydration error is still thrown in red above, but this is printed below:

Screen Shot 2022-04-03 at 11 14 40 AM

To tophat this, remove the Suspense boundary around the children inside Layout.server.jsx.


Before submitting the PR, please make sure you do the following:

  • Read the Contributing Guidelines
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123)
  • Update docs in this repository according to your change
  • Run yarn changeset add if this PR cause a version bump based on Keep a Changelog and adheres to Semantic Versioning

@jplhomer jplhomer requested a review from a team April 3, 2022 16:22
{
onRecoverableError(e: any) {
if (__DEV__) {
console.log(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this, I think it makes sense! What if in dev mode were also at most to only print this once?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deal

Copy link
Contributor

@frandiox frandiox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@jplhomer jplhomer merged commit 0348808 into v1.x-2022-07 Apr 5, 2022
@jplhomer jplhomer deleted the jl-recoverable-error branch April 5, 2022 13:32
This was referenced Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants