Subscribe on changes!

onServerPrefetch produces an invalid warning on ssr

avatar
Nov 1st 2022

The playground doesn't seem to be working correctly; look at this, it has a warning about hydration:

62272b3a4f6330fd4e52ff974ecf5fa

avatar
Nov 2nd 2022

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

avatar
Nov 2nd 2022

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

image

https://github.com/vuejs/core/blob/f67bb500b6071bc0e55a89709a495a27da73badd/packages/runtime-core/src/apiLifecycle.ts#L23

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.

https://github.com/vuejs/core/blob/f67bb500b6071bc0e55a89709a495a27da73badd/packages/runtime-core/src/component.ts#L660

https://github.com/vuejs/core/blob/f67bb500b6071bc0e55a89709a495a27da73badd/packages/runtime-core/src/component.ts#L564

PS: It's work fine in the unit test case, but work failed in SSR mode playground and Nuxt.

avatar
Nov 4th 2022

@webfansplz you are right, the problem happens with an empty call

avatar
Nov 5th 2022

@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

avatar
Nov 5th 2022

@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

avatar
Nov 19th 2022

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.

Solution fork

// const data = ref(false)
const data = useState('data')