fix(slots): differentiate dynamic/static compiled slots

fix #1557
This commit is contained in:
Evan You
2020-07-13 12:36:41 -04:00
parent ba3b3cdda9
commit 65beba98fe
7 changed files with 143 additions and 120 deletions

View File

@@ -135,7 +135,7 @@ export function buildSlots(
let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0
// with `prefixIdentifiers: true`, this can be further optimized to make
// it dynamic only when the slot actually uses the scope variables.
if (!__BROWSER__ && context.prefixIdentifiers) {
if (!__BROWSER__ && !context.ssr && context.prefixIdentifiers) {
hasDynamicSlots = hasScopeRef(node, context.identifiers)
}
@@ -144,6 +144,9 @@ export function buildSlots(
const onComponentSlot = findDir(node, 'slot', true)
if (onComponentSlot) {
const { arg, exp } = onComponentSlot
if (arg && !isStaticExp(arg)) {
hasDynamicSlots = true
}
slotsProperties.push(
createObjectProperty(
arg || createSimpleExpression('default', true),
@@ -317,7 +320,12 @@ export function buildSlots(
let slots = createObjectExpression(
slotsProperties.concat(
createObjectProperty(`_`, createSimpleExpression(`1`, false))
createObjectProperty(
`_`,
// 2 = compiled but dynamic = can skip normalization, but must run diff
// 1 = compiled and static = can skip normalization AND diff as optimized
createSimpleExpression(hasDynamicSlots ? `2` : `1`, false)
)
),
loc
) as SlotsExpression