fix(nuxt): wrap slot with h() in ClientOnly (#30664)

This commit is contained in:
Julien Huang 2025-01-20 07:47:51 +01:00 committed by GitHub
parent e5a7c19b18
commit c5a78ea154
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -14,7 +14,7 @@ export default defineComponent({
inheritAttrs: false, inheritAttrs: false,
props: ['fallback', 'placeholder', 'placeholderTag', 'fallbackTag'], props: ['fallback', 'placeholder', 'placeholderTag', 'fallbackTag'],
setup (_, { slots, attrs }) { setup (props, { slots, attrs }) {
const mounted = ref(false) const mounted = ref(false)
onMounted(() => { mounted.value = true }) onMounted(() => { mounted.value = true })
// Bail out of checking for pages/layouts as they might be included under `<ClientOnly>` 🤷‍♂️ // Bail out of checking for pages/layouts as they might be included under `<ClientOnly>` 🤷‍♂️
@ -24,10 +24,10 @@ export default defineComponent({
nuxtApp._isNuxtLayoutUsed = true nuxtApp._isNuxtLayoutUsed = true
} }
provide(clientOnlySymbol, true) provide(clientOnlySymbol, true)
return (props: any) => { return () => {
if (mounted.value) { return slots.default?.() } if (mounted.value) { return slots.default?.() }
const slot = slots.fallback || slots.placeholder const slot = slots.fallback || slots.placeholder
if (slot) { return slot() } if (slot) { return h(slot) }
const fallbackStr = props.fallback || props.placeholder || '' const fallbackStr = props.fallback || props.placeholder || ''
const fallbackTag = props.fallbackTag || props.placeholderTag || 'span' const fallbackTag = props.fallbackTag || props.placeholderTag || 'span'
return createElementBlock(fallbackTag, attrs, fallbackStr) return createElementBlock(fallbackTag, attrs, fallbackStr)