maoberlehner / vue-lazy-hydration

Lazy Hydration of Server-Side Rendered Vue.js Components
MIT License
1.19k stars 52 forks source link

Try to understand the behavior #67

Closed JBustin closed 3 years ago

JBustin commented 4 years ago

Hello,

I use nuxtjs v2.14.3 as universal and the latest beta version of vue-lazy-hydration. I have a hidden navigation tool that I hydrate only when the tool is opened for the first time (ssr-only + trigger-hydration). It works as expected for no-mobile, but not for my mobile version (responsive). Notice that nuxtjs generates the mobile version.

To be more precise, mobile and desktop are two different lazy components, called by dynamic component syntax:

<template>
  ...
    <LazyHydrate ssr-only :trigger-hydration="onceOpenNav">
      <component :is="isMobile ? 'HeaderMainNavMobilePanel' : 'HeaderMainNavPanel'>
        ...
      </component>
    </LazyHydrate>
  ...
</template>

export default {
  components: {
    HeaderMainNavPanel: () =>
      import('~/components/layout/header/HeaderMainNavPanel/HeaderMainNavPanel'),
    HeaderMainNavMobilePanel: () =>
      import('~/components/layout/header/HeaderMainNavMobilePanel/HeaderMainNavMobilePanel'),
  },
  ...
}

My problem is resolved by commenting this line: https://github.com/maoberlehner/vue-lazy-hydration/blob/master/src/LazyHydrate.js#L160

I'm surprising because:

Does someone have an explanation, a trick, any idea ?

Regards

maoberlehner commented 3 years ago

Hello @JBustin ! I highly recommend you to not do stuff like <component :is="isMobile ? 'HeaderMainNavMobilePanel' : 'HeaderMainNavPanel'> with Nuxt! If SSR HTML does not match client-side rendered HTML you're heading for trouble.

Make sure SSR HTML does always match client HTML 100%!