Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(nuxt): remove fragment from createClientOnly #7774

Merged
merged 11 commits into from Oct 3, 2022
16 changes: 10 additions & 6 deletions packages/nuxt/src/app/components/client-only.mjs
@@ -1,4 +1,4 @@
import { ref, onMounted, defineComponent, createElementBlock, h, Fragment } from 'vue'
import { ref, onMounted, defineComponent, createElementBlock, h } from 'vue'

export default defineComponent({
name: 'ClientOnly',
Expand Down Expand Up @@ -31,7 +31,7 @@ export function createClientOnly (component) {
// override the component render (non script setup component)
clone.render = (ctx, ...args) => {
return ctx.mounted$
? h(Fragment, ctx.$attrs ?? ctx._.attrs, component.render(ctx, ...args))
? h(component.render(ctx, ...args))
: h('div', ctx.$attrs ?? ctx._.attrs)
}
} else if (clone.template) {
Expand All @@ -51,10 +51,14 @@ export function createClientOnly (component) {
return typeof setupState !== 'function'
? { ...setupState, mounted$ }
: (...args) => {
return mounted$.value
// use Fragment to avoid oldChildren is null issue
? h(Fragment, ctx.attrs, setupState(...args))
: h('div', ctx.attrs)
if (mounted$.value) {
const res = setupState(...args)
return (res.children === null || typeof res.children === 'string')
? createElementBlock(res.type, res.props, res.children, res.patchFlag, res.dynamicProps, res.shapeFlag)
: h(res)
} else {
return h('div', ctx.attrs)
}
}
})
}
Expand Down