vue-lazy-hydration icon indicating copy to clipboard operation
vue-lazy-hydration copied to clipboard

Hydrate `never` doesn't seem to work

Open hsks opened this issue 4 years ago • 4 comments
trafficstars

Hi, Thanks for this amazing library. I was trying this out with nuxt 2.x with hydrate never mode. The code looks something like this:

<LazyHydrate never>
<Component-A>
</LazyHydrate>

Component-A:
<template>
Ssr mode is {{ isSsr }}
</template>

isSsr is a computed property that simply returns the value of process.server.

For some reason, as soon as the page is rendered on the client side, Component A resolves to Ssr mode is false. It works fine when I turn javascript off, which means it's rendered correctly on the server side. I'm using nuxt in universal mode. Any idea how I can prevent hydration of such static components?

hsks avatar Oct 11 '21 11:10 hsks

As I understand the default value of isSsr is "false" and as I understand you want to transfer server side value to the client, right? If I remember correctly it wont work. LazyHydrate is a client side tool, this is the reason why you see "false", ie on the client it falls back to the default "false" value.

TitanFighter avatar Oct 11 '21 22:10 TitanFighter

Hi, Thanks for the reply. I agree LazyHydrate works on the client side. But given the never hydrate prop, shouldn't it block any hydration on the client side. This in turn will result is only the server side content rendered -? hence the expected true value.

hsks avatar Oct 12 '21 03:10 hsks

I had similar situation long time ago and if I remember correctly I came to the conclusion that: in case of "never" LazyHydrate simply reads default value of variable (as I understand, it is "false" in your case).

TitanFighter avatar Oct 12 '21 14:10 TitanFighter

It should be true in any case, since process.server is true during server side rendering. It will only become false if client hydrates the component. And it seems it has something to do with my app configuration specifically. I just configured a fresh nuxt app and used lazy hydrate, it works fine

hsks avatar Oct 12 '21 14:10 hsks