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

Hydration mismatch error because initial CSR render differs from SSR render #1432

Closed
fabis94 opened this issue Nov 16, 2022 · 5 comments
Closed

Comments

@fabis94
Copy link

fabis94 commented Nov 16, 2022

Describe the bug
When using useQuery off @vue/apollo-composable to load some data from an API in a SSR-supported app (e.g. Nuxt 3), Vue reports hydration mismatch errors during CSR even though SSR rendered the page correctly and after multiple passes CSR renders it correctly as well. The problem here is that this only happens after multiple render passes.

It seems that SSR renders everything correctly, and CSR also does, but only on 2nd render pass. On initial render, even tho the Apollo cache is filled, it returns undefined at first, which causes Vue to report that there's a hydration mismatch.

image

(the error message seems off as well, its actually the inverse: SSR returns the full string, while CSR returns 'undefined' on first render pass)

To Reproduce
Repo: https://github.com/fabis94/nuxt3-apollo-hydration-error

See instructions in readme

Expected behavior
During CSR useQuery should return the already pre-cached data (from SSR) on first render, instead of returning undefined at first and then only getting the data out from cache on 2nd render. This should make the Vue hydration errors disappear.

Versions
vue: 3.2.45
@vue/apollo-composable: 4.0.0-beta.1
@vue/apollo-ssr: 4.0.0-alpha.18
@apollo/client: 3.7.0

Additional context

@fabis94
Copy link
Author

fabis94 commented Dec 12, 2022

Here's a PR with my fix: #1436

@productdevbook
Copy link

Great job, so how do we add header authorization here. In particular, a cookie that is http only.

@fabis94
Copy link
Author

fabis94 commented Dec 13, 2022

@productdevbook I'm confused, because these changes by definition only return what's already in the cache instead of triggering any requests or anything that would need headers or authentication cookies.

@99linesofcode
Copy link

Sooo, what is preventing this from getting merged?

@99linesofcode
Copy link

@Akryum thanks a lot for taking a stab at this so quickly! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants