-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
onServerPrefetch with useId
cause hydration issue if treeshaken client-side
#12591
Comments
When rendering on the CSR, it checks if the component contains core/packages/runtime-core/src/component.ts Lines 876 to 879 in 1755ac0
markAsynvBoundary to make it consistent with SSR behavior.
|
In Nuxt side, we could either treeshake only the callback of But i'm not really in favour of the second one tho. Or maybe can we leave it to vue: we remove the treeshaking of cc @danielroe |
imho, it would be nice to tree-shake it on the Vue side |
I'm happy to remove treeshaking of // Server side
if (import.meta.server && fetchOnServer && options.immediate) {
const promise = initialFetch()
if (getCurrentInstance()) {
onServerPrefetch(() => promise)
} else {
nuxtApp.hook('app:created', async () => { await promise })
}
}
In other words, we'd have to artificially add an 'onServerPrefetch' which awaits an empty promise in order to 'match'. More than happy to do that, but is there another way? |
Yes, useAsyncData is a too specific case to be handled by vue-compiler. In the meantime, we can try the second option using an empty |
Vue compiler cannot find all |
Vue version
3.5.13
Link to minimal reproduction
https://stackblitz.com/edit/vue-ssr-example-bsqzmafk?file=app.js,client.js,server.js
Steps to reproduce
open your console and see there's a hydration mismatch.
Comp.vue
's useId is not retturning the same value server side and client sideWhat is expected?
no hydration issue due to
useId
What is actually happening?
The cause of this issue is that we run
onServerPrefetch
only server-side.This happen in Nuxt because we treeshake
onServerPrefetch
in client-bundle and we also wraponServerPrefetch
withimport.meta.server
flag inuseAsyncData
composable.In runtime, this results into the component being marked as async boudary only server side with
markAsyncBoundary
but not client side --> resulting to a hydration issue becauseuseId
returns different strings.System Info
No response
Any additional comments?
Nuxt issue nuxt/nuxt#30289
The text was updated successfully, but these errors were encountered: