onServerPrefetch produces an invalid warning on ssr
Vue version
3
Link to minimal reproduction
Steps to reproduce
- In
Setup()
, defineconst data = ref(false)
; - In the
onServerPrefetch
life Lifecycle, set thedata.value = true
; - Get the
data
in the template is false;
What is expected?
data.value
is true
What is actually happening?
data.value
is false
System Info
No response
Any additional comments?
https://vuejs.org/api/composition-api-lifecycle.html#onserverprefetch No response
The playground doesn't seem to be working correctly; look at this, it has a warning about hydration:
The example on the docs is missing the serialization of the data. Without it, the client is not aware of the initial state when it renders and thus creates a Hydration mismatch. I would say this should be fixed in docs instead
The example on the docs is missing the serialization of the data. Without it, the client is not aware of the initial state when it renders and thus creates a Hydration mismatch. I would say this should be fixed in docs instead
It’s seems a bug, It’ve set the currentInstance before call the setup function.
But the target output undefined when call the onServerPrefetch
hook, They don't seem to refer to the same currentInstance
in the setup function scope.
PS: It's work fine in the unit test case, but work failed in SSR mode playground and Nuxt.
@webfansplz you are right, the problem happens with an empty call
@posva I believe there is a bug in the online sfc-playground because it works fine in my local sfc-playground.
@webfansplz you are right, the problem happens with an empty call
and there is a warning @zhangzhonghe mentioned
VM682 about:srcdoc:160 [Vue warn]: Hydration text content mismatch in <h1>:
- Client: true
- Server: false
at <Repl>
They don't seem to refer to the same currentInstance in the setup function scope.
@webfansplz that's the problem about the online sfc-playground. see https://github.com/vuejs/core/issues/7011#issuecomment-1301719397
@posva I believe there is a bug in the online sfc-playground because it works fine in my local sfc-playground.
@webfansplz you are right, the problem happens with an empty call
and there is a warning @zhangzhonghe mentioned
VM682 about:srcdoc:160 [Vue warn]: Hydration text content mismatch in <h1>: - Client: true - Server: false at <Repl>
They don't seem to refer to the same currentInstance in the setup function scope.
@webfansplz that's the problem about the online sfc-playground. see #7011 (comment)
Yes, I also found the sfc-playground's issue, which caused the currentInstance
reference problem in SSR mode.
But it doesn't seem to work very well in Nuxt3. Mini Repo
Hello, I was having this question as well. After reading the docs on state management of Nuxt3.
@webfansplz In your example Mini Repo, you can use useState
instead of ref
, as this is shared across the server and client. Solving the hydration mismatch error.
// const data = ref(false)
const data = useState('data')