vuejs / vitepress

Vite & Vue powered static site generator.
https://vitepress.dev
MIT License
11.48k stars 1.86k forks source link

ant-design-vue some components cannot render twice under vitepress build. #3718

Closed qianyuhouse closed 1 month ago

qianyuhouse commented 1 month ago

Describe the bug

dependencies used

A custom layout in .vitepress/theme like below.

<template>
  <div>
    <Button @click="handleClick">切换 显示和隐藏</Button>
    <Empty v-if="visible" />
    <Empty />
  </div>
</template>
<script lang="ts" setup>
import { Empty } from 'ant-design-vue';
import { ref } from "vue"
const visible = ref(true)

const handleClick = () => {
  visible.value = !visible.value

}
</script>

Reproduction

Steps

  1. build.
    vitepress build docs.
  2. serve. vitepress serve docs.
  3. Click Button in the page.

Problem I face

Everything is normal at the first.But when I click the button to change the element in the page, 'Empty' component cannot be rendered.

image

Expected behavior

Expected.

No matter re-render times, I hope it can be rendered normal.

image

System Info

There's no any extra info.

Additional context

No response

Validations

brc-dd commented 1 month ago

That component is broken in SSR. Please create an issue at their repo instead (most likely its same as https://github.com/vueComponent/ant-design-vue/issues/6939). The issue is reproducible with Nuxt too.

qianyuhouse commented 1 month ago

That component is broken in SSR. Please create an issue at their repo instead (most likely its same as vueComponent/ant-design-vue#6939). The issue is reproducible with Nuxt too.

thanks

brc-dd commented 1 month ago

Wrapping it with <ClientOnly> doesn't work either. My guess is their SSR style rendering thing they added in v4 has bugs. You probably can use older versions I guess or switch to client-side vite app or a different component library.

qianyuhouse commented 1 month ago

Wrapping it with <ClientOnly> doesn't work either. My guess is their SSR style rendering thing they added in v4 has bugs. You probably can use older versions I guess or switch to client-side vite app or a different component library.

I have tried using antd@v3 wrapped with <ClientOnly>, but it doesn't work either. I have looked at their source code, that image Vnode is declared at the global environment and it's a constant. And Vue3 docs notes that Vnode Must Be Unique.I don't know whether it's the cause or not.