mirror of https://github.com/vuejs/core.git
chore: Merge branch 'edison/fix/vaporSlotFallback' into edison/feat/fowardedSlots
This commit is contained in:
commit
92399d9f8f
|
@ -152,7 +152,6 @@ export const createFor = (
|
||||||
// render fallback nodes
|
// render fallback nodes
|
||||||
if (frag.fallback) {
|
if (frag.fallback) {
|
||||||
insert((frag.nodes[0] = frag.fallback()), parent!, parentAnchor)
|
insert((frag.nodes[0] = frag.fallback()), parent!, parentAnchor)
|
||||||
oldBlocks = []
|
|
||||||
isFallback = true
|
isFallback = true
|
||||||
}
|
}
|
||||||
} else if (!getKey) {
|
} else if (!getKey) {
|
||||||
|
@ -341,9 +340,9 @@ export const createFor = (
|
||||||
|
|
||||||
if (!isFallback) {
|
if (!isFallback) {
|
||||||
frag.nodes = [(oldBlocks = newBlocks)]
|
frag.nodes = [(oldBlocks = newBlocks)]
|
||||||
if (parentAnchor) {
|
if (parentAnchor) frag.nodes.push(parentAnchor)
|
||||||
frag.nodes.push(parentAnchor)
|
} else {
|
||||||
}
|
oldBlocks = []
|
||||||
}
|
}
|
||||||
setActiveSub(prevSub)
|
setActiveSub(prevSub)
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,18 +73,19 @@ export class DynamicFragment extends VaporFragment {
|
||||||
|
|
||||||
if (this.fallback) {
|
if (this.fallback) {
|
||||||
// set fallback for nested fragments
|
// set fallback for nested fragments
|
||||||
const isFrag = isFragment(this.nodes)
|
const hasNestedFragment = isFragment(this.nodes)
|
||||||
if (isFrag) {
|
if (hasNestedFragment) {
|
||||||
setFragmentFallback(this.nodes as VaporFragment, this.fallback)
|
setFragmentFallback(this.nodes as VaporFragment, this.fallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isValidBlock(this.nodes)) {
|
const invalidFragment = findInvalidFragment(this)
|
||||||
|
if (invalidFragment) {
|
||||||
parent && remove(this.nodes, parent)
|
parent && remove(this.nodes, parent)
|
||||||
const scope = this.scope || (this.scope = new EffectScope())
|
const scope = this.scope || (this.scope = new EffectScope())
|
||||||
scope.run(() => {
|
scope.run(() => {
|
||||||
if (isFrag) {
|
// for nested fragments, render invalid fragment's fallback
|
||||||
// render fragment's fallback
|
if (hasNestedFragment) {
|
||||||
renderFragmentFallback(this.nodes as VaporFragment)
|
renderFragmentFallback(invalidFragment)
|
||||||
} else {
|
} else {
|
||||||
this.nodes = this.fallback!() || []
|
this.nodes = this.fallback!() || []
|
||||||
}
|
}
|
||||||
|
@ -101,9 +102,10 @@ function setFragmentFallback(
|
||||||
fragment: VaporFragment,
|
fragment: VaporFragment,
|
||||||
fallback: BlockFn | undefined,
|
fallback: BlockFn | undefined,
|
||||||
): void {
|
): void {
|
||||||
if (!fragment.fallback) {
|
// stop recursion if fragment has its own fallback
|
||||||
|
if (fragment.fallback) return
|
||||||
|
|
||||||
fragment.fallback = fallback
|
fragment.fallback = fallback
|
||||||
}
|
|
||||||
if (isFragment(fragment.nodes)) {
|
if (isFragment(fragment.nodes)) {
|
||||||
setFragmentFallback(fragment.nodes, fallback)
|
setFragmentFallback(fragment.nodes, fallback)
|
||||||
}
|
}
|
||||||
|
@ -113,17 +115,20 @@ function renderFragmentFallback(fragment: VaporFragment): void {
|
||||||
if (fragment instanceof ForFragment) {
|
if (fragment instanceof ForFragment) {
|
||||||
fragment.nodes[0] = [fragment.fallback!() || []] as Block[]
|
fragment.nodes[0] = [fragment.fallback!() || []] as Block[]
|
||||||
} else if (fragment instanceof DynamicFragment) {
|
} else if (fragment instanceof DynamicFragment) {
|
||||||
const nodes = fragment.nodes
|
|
||||||
if (isFragment(nodes)) {
|
|
||||||
renderFragmentFallback(nodes)
|
|
||||||
} else {
|
|
||||||
fragment.update(fragment.fallback)
|
fragment.update(fragment.fallback)
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// vdom slots
|
// vdom slots
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function findInvalidFragment(fragment: VaporFragment): VaporFragment | null {
|
||||||
|
if (isValidBlock(fragment.nodes)) return null
|
||||||
|
|
||||||
|
return isFragment(fragment.nodes)
|
||||||
|
? findInvalidFragment(fragment.nodes) || fragment
|
||||||
|
: fragment
|
||||||
|
}
|
||||||
|
|
||||||
export function isFragment(val: NonNullable<unknown>): val is VaporFragment {
|
export function isFragment(val: NonNullable<unknown>): val is VaporFragment {
|
||||||
return val instanceof VaporFragment
|
return val instanceof VaporFragment
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue