fix(ssr): fix ssr scopeId on component root
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { ComponentInternalInstance, Slot, Slots } from 'vue'
|
||||
import { ComponentInternalInstance, Slots } from 'vue'
|
||||
import { Props, PushFn, renderVNodeChildren } from '../render'
|
||||
|
||||
export type SSRSlots = Record<string, SSRSlot>
|
||||
@@ -21,13 +21,16 @@ export function ssrRenderSlot(
|
||||
push(`<!--[-->`)
|
||||
const slotFn = slots[slotName]
|
||||
if (slotFn) {
|
||||
if (slotFn.length > 1) {
|
||||
// only ssr-optimized slot fns accept more than 1 arguments
|
||||
const scopeId = parentComponent && parentComponent.type.__scopeId
|
||||
slotFn(slotProps, push, parentComponent, scopeId ? ` ${scopeId}-s` : ``)
|
||||
} else {
|
||||
const scopeId = parentComponent && parentComponent.type.__scopeId
|
||||
const ret = slotFn(
|
||||
slotProps,
|
||||
push,
|
||||
parentComponent,
|
||||
scopeId ? ` ${scopeId}-s` : ``
|
||||
)
|
||||
if (Array.isArray(ret)) {
|
||||
// normal slot
|
||||
renderVNodeChildren(push, (slotFn as Slot)(slotProps), parentComponent)
|
||||
renderVNodeChildren(push, ret, parentComponent)
|
||||
}
|
||||
} else if (fallbackRenderFn) {
|
||||
fallbackRenderFn()
|
||||
|
||||
@@ -109,11 +109,23 @@ function renderComponentSubTree(
|
||||
|
||||
if (comp.ssrRender) {
|
||||
// optimized
|
||||
// resolve fallthrough attrs
|
||||
let attrs =
|
||||
instance.type.inheritAttrs !== false ? instance.attrs : undefined
|
||||
|
||||
// inherited scopeId
|
||||
const scopeId = instance.vnode.scopeId
|
||||
const treeOwnerId = instance.parent && instance.parent.type.__scopeId
|
||||
const slotScopeId =
|
||||
treeOwnerId && treeOwnerId !== scopeId ? treeOwnerId + '-s' : null
|
||||
if (scopeId || slotScopeId) {
|
||||
attrs = { ...attrs }
|
||||
if (scopeId) attrs[scopeId] = ''
|
||||
if (slotScopeId) attrs[slotScopeId] = ''
|
||||
}
|
||||
|
||||
// set current rendering instance for asset resolution
|
||||
setCurrentRenderingInstance(instance)
|
||||
// fallthrough attrs
|
||||
const attrs =
|
||||
instance.type.inheritAttrs !== false ? instance.attrs : undefined
|
||||
comp.ssrRender(instance.proxy, push, instance, attrs)
|
||||
setCurrentRenderingInstance(null)
|
||||
} else if (instance.render) {
|
||||
|
||||
Reference in New Issue
Block a user