refactor: fix implementation of SFC :slotted id handling

fix #2892
This commit is contained in:
Evan You
2021-03-05 11:10:06 -05:00
parent cc975c1292
commit aea88c3280
36 changed files with 723 additions and 457 deletions

View File

@@ -203,6 +203,12 @@ export function ssrProcessComponent(
vnodeBranch
)
}
// component is inside a slot, inherit slot scope Id
if (context.withSlotScopeId) {
node.ssrCodegenNode!.arguments.push(`_scopeId`)
}
if (typeof component === 'string') {
// static component
context.pushStatement(

View File

@@ -21,9 +21,11 @@ export const ssrTransformSlotOutlet: NodeTransform = (node, context) => {
`_ctx.$slots`,
slotName,
slotProps || `{}`,
`null`, // fallback content placeholder.
// fallback content placeholder. will be replaced in the process phase
`null`,
`_push`,
`_parent`
`_parent`,
context.scopeId ? `"${context.scopeId}-s"` : `null`
]
)
}
@@ -34,6 +36,7 @@ export function ssrProcessSlotOutlet(
context: SSRTransformContext
) {
const renderCall = node.ssrCodegenNode!
// has fallback content
if (node.children.length) {
const fallbackRenderFn = createFunctionExpression([])
@@ -41,5 +44,13 @@ export function ssrProcessSlotOutlet(
// _renderSlot(slots, name, props, fallback, ...)
renderCall.arguments[3] = fallbackRenderFn
}
// Forwarded <slot/>. Add slot scope id
if (context.withSlotScopeId) {
const scopeId = renderCall.arguments[6] as string
renderCall.arguments[6] =
scopeId === `null` ? `_scopeId` : `${scopeId} + _scopeId`
}
context.pushStatement(node.ssrCodegenNode!)
}