fix(ssr): fix ssr scopeId on component root

This commit is contained in:
Evan You
2020-06-27 00:25:07 -04:00
parent 978d9522e8
commit afe13e0584
7 changed files with 137 additions and 46 deletions

View File

@@ -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()