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

@@ -63,7 +63,7 @@ export function createHydrationFunctions(
return
}
hasMismatch = false
hydrateNode(container.firstChild!, vnode, null, null)
hydrateNode(container.firstChild!, vnode, null, null, null)
flushPostFlushCbs()
if (hasMismatch && !__TEST__) {
// this error should show up in production
@@ -76,6 +76,7 @@ export function createHydrationFunctions(
vnode: VNode,
parentComponent: ComponentInternalInstance | null,
parentSuspense: SuspenseBoundary | null,
slotScopeIds: string[] | null,
optimized = false
): Node | null => {
const isFragmentStart = isComment(node) && node.data === '['
@@ -85,6 +86,7 @@ export function createHydrationFunctions(
vnode,
parentComponent,
parentSuspense,
slotScopeIds,
isFragmentStart
)
@@ -147,6 +149,7 @@ export function createHydrationFunctions(
vnode,
parentComponent,
parentSuspense,
slotScopeIds,
optimized
)
}
@@ -164,6 +167,7 @@ export function createHydrationFunctions(
vnode,
parentComponent,
parentSuspense,
slotScopeIds,
optimized
)
}
@@ -171,6 +175,7 @@ export function createHydrationFunctions(
// when setting up the render effect, if the initial vnode already
// has .el set, the component will perform hydration instead of mount
// on its sub-tree.
vnode.slotScopeIds = slotScopeIds
const container = parentNode(node)!
const hydrateComponent = () => {
mountComponent(
@@ -205,6 +210,7 @@ export function createHydrationFunctions(
vnode as TeleportVNode,
parentComponent,
parentSuspense,
slotScopeIds,
optimized,
rendererInternals,
hydrateChildren
@@ -217,6 +223,7 @@ export function createHydrationFunctions(
parentComponent,
parentSuspense,
isSVGContainer(parentNode(node)!),
slotScopeIds,
optimized,
rendererInternals,
hydrateNode
@@ -238,6 +245,7 @@ export function createHydrationFunctions(
vnode: VNode,
parentComponent: ComponentInternalInstance | null,
parentSuspense: SuspenseBoundary | null,
slotScopeIds: string[] | null,
optimized: boolean
) => {
optimized = optimized || !!vnode.dynamicChildren
@@ -291,6 +299,7 @@ export function createHydrationFunctions(
el,
parentComponent,
parentSuspense,
slotScopeIds,
optimized
)
let hasWarned = false
@@ -330,6 +339,7 @@ export function createHydrationFunctions(
container: Element,
parentComponent: ComponentInternalInstance | null,
parentSuspense: SuspenseBoundary | null,
slotScopeIds: string[] | null,
optimized: boolean
): Node | null => {
optimized = optimized || !!parentVNode.dynamicChildren
@@ -346,6 +356,7 @@ export function createHydrationFunctions(
vnode,
parentComponent,
parentSuspense,
slotScopeIds,
optimized
)
} else {
@@ -365,7 +376,8 @@ export function createHydrationFunctions(
null,
parentComponent,
parentSuspense,
isSVGContainer(container)
isSVGContainer(container),
slotScopeIds
)
}
}
@@ -377,8 +389,16 @@ export function createHydrationFunctions(
vnode: VNode,
parentComponent: ComponentInternalInstance | null,
parentSuspense: SuspenseBoundary | null,
slotScopeIds: string[] | null,
optimized: boolean
) => {
const { slotScopeIds: fragmentSlotScopeIds } = vnode
if (fragmentSlotScopeIds) {
slotScopeIds = slotScopeIds
? slotScopeIds.concat(fragmentSlotScopeIds)
: fragmentSlotScopeIds
}
const container = parentNode(node)!
const next = hydrateChildren(
nextSibling(node)!,
@@ -386,6 +406,7 @@ export function createHydrationFunctions(
container,
parentComponent,
parentSuspense,
slotScopeIds,
optimized
)
if (next && isComment(next) && next.data === ']') {
@@ -405,6 +426,7 @@ export function createHydrationFunctions(
vnode: VNode,
parentComponent: ComponentInternalInstance | null,
parentSuspense: SuspenseBoundary | null,
slotScopeIds: string[] | null,
isFragment: boolean
): Node | null => {
hasMismatch = true
@@ -446,7 +468,8 @@ export function createHydrationFunctions(
next,
parentComponent,
parentSuspense,
isSVGContainer(container)
isSVGContainer(container),
slotScopeIds
)
return next
}