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

Better reporting of hydration mismatches #8900

Open
rudolfbyker opened this issue Aug 2, 2023 · 4 comments
Open

Better reporting of hydration mismatches #8900

rudolfbyker opened this issue Aug 2, 2023 · 4 comments
Labels
✨ feature request New feature or request

Comments

@rudolfbyker
Copy link

rudolfbyker commented Aug 2, 2023

What problem does this feature solve?

It is currently hard to debug:

  • Hydration mismatches happening in production but not in development.
  • Hydration mismatches happening for some but not all users in the field, but not in the lab.
  • Hydration mismatches happening only at certain times / dates.
  • Hydration mismatches happening due to external factors like misbehaving APIs.

Since Vue 3.4 is is possible to include details about hydration mismatches in production using a compile time flag: https://vuejs.org/api/compile-time-flags.html#VUE_PROD_HYDRATION_MISMATCH_DETAILS , but it still just goes to the console.

The relevant code starts here:

const handleMismatch = (

It would be great if we could provide a way of plugging this into something like Sentry for in-production, in-the-field collection of mismatch info.

What does the proposed API look like?

Since a mismatch is not a thrown error (and should not be), it currently just logs to the console. It would be nice if we could pass in some kind of onHydrationMismatch function, which gets called instead of warn.

It should get called once for each mismatch, if possible.

It should receive as arguments any DOM nodes and virtual nodes related to the mismatch.

@rudolfbyker rudolfbyker added the ✨ feature request New feature or request label Aug 2, 2023
@FreshRob
Copy link

FreshRob commented Oct 5, 2023

I concur with this statement.

Recently we got hydration mismatches in production, and it took modifying the runtime-core to allow the dev logs for hydration

In our case it due to using toLocaleString and this would cause mismatching between the server and the client.

Would an acceptable solution in the short term be to add a defineOption to enable HydrationLogging vs using NODE_ENV === "production"

@FreshRob
Copy link

FreshRob commented Oct 9, 2023

Following this, with the extra logging, we also saw some users using tools to translate from English to another language which then also causes a mismatch, without this extra logging it wouldn't of been possible to figure that out.

@rudolfbyker
Copy link
Author

Updated the original post for Vue 3.4

@rudolfbyker
Copy link
Author

A workaround specifically for Sentry: Use this integration https://docs.sentry.io/platforms/javascript/configuration/integrations/captureconsole/ along with the compile time flag https://vuejs.org/api/compile-time-flags.html#VUE_PROD_HYDRATION_MISMATCH_DETAILS . But this is not a general solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants