Ziwen Wang
Ziwen Wang

Reputation: 31

SSR and keep-alive issue in Vue 3: dynamic component

<template>
      <div class="default-layout">
          <router-view v-slot="{ index }">
            <keep-alive>
              <component :is="index" :key="route.fullPath" />
            </keep-alive>
          </router-view> 
      </div>
</template>
    
<script lang="ts">
    import { defineComponent} from "vue";
    import { useRoute } from "vue-router";
    import Index from "@/pages/index";
    
    export default defineComponent({
      name: "app",
      components: {
        Index,
      },
      setup: () => {
        const route = useRoute();
       
        return { route, index: Index };
      },
    });

</script>

It will lead to an error while rendering: Error message

[Vue warn]: Hydration node mismatch:
- Client vnode: Symbol(Comment) 
- Server rendered DOM: <!--[--> (start of fragment) 
  at <KeepAlive> 
  at <RouterView key=0 > 
  at <App>

Hydration children mismatch in <div>: server rendered element contains fewer child nodes than client vdom. 

Hydration completed but contains mismatches.

What shall I do to fix this issue?

Upvotes: 3

Views: 1524

Answers (1)

Ovidiu
Ovidiu

Reputation: 151

I believe this is a bug. You can follow it at https://github.com/vuejs/vue-next/issues/4817

At the time of this writing, it was not yet confirmed by Vue maintainers.

Upvotes: 3

Related Questions