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

<LazyHydrate> suppresses <client-only>

Open TitanFighter opened this issue 4 years ago • 4 comments

In this case:

<LazyHydrate when-visible>
  <b-container>

    ......
  
    <client-only>
      <TheVisitedTours v-show=toursRecentlyViewed.length" />
    </client-only>
  </b-container>
</LazyHydrate>

<client-only> does not work.

Some details.

TitanFighter avatar Dec 14 '20 18:12 TitanFighter

Pleas provide a minimal reproduction when you're still interested in a fix.

maoberlehner avatar Jan 04 '21 05:01 maoberlehner

I think he about hydration error if use client-only and lazy-hydration Reproduce It may be usefull, for create component only for client and only when-idle or when-visible

Kolobok12309 avatar Aug 19 '21 11:08 Kolobok12309

For us this is happening consistently but not in all places where we use <LazyHydrate>. Somewhere <client-only> within <LazyHydrate> works, somewhere not.

But in the end it's a ['<!-- -->'] vs [] conflict.

The workaround is to create your own <ClientOnly> that consistently renders a span as opposed to a comment vs. nothing.

const ClientOnlyFixed = defineComponent({
  setup(props, { slots }) {
    const render = ref(false);
    onMounted(() => (render.value = true));
    return () => render.value ? h('span', {}, slots.default()) : h('span');
  },
});

MartinMalinda avatar Nov 12 '21 13:11 MartinMalinda

@MartinMalinda @maoberlehner I'm experiencing a similar problem as above from Martin, where using v-if or v-for results in this line this.$el.nodeType === Node.COMMENT_NODE getting triggered, overwriting the never parameter.

<LazyHydrate never>
   <div v-if="couldBeTrueOrFalseDoesntMatter" @click="doSomething">Click Me</div>
</LazyHydrate>
<LazyHydrate v-for="a in array" :key="a" never>
   <div>{{ a }}</div>
</LazyHydrate>

Edit: I think I've fixed it. The problem was with async components (() => import) and using mounted hook for API requests, because the mounted hook within lazy-hydration was called before it finished the api call. Using classic import and fetch hook resulted in this.$el being the actual object, not just an empty comment (at least for v-for) https://github.com/nuxt/nuxt.js/issues/8981

tre-dev avatar Dec 07 '21 14:12 tre-dev