Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): Correct update renders both old and new dynamic child node arrays are empty #7266

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f588de4
fix(runtime-core): Correct update renders both old and new dynamic ch…
baiwusanyu-c Dec 2, 2022
7751efa
fix(runtime-core): added unit test(#7256)
baiwusanyu-c Dec 2, 2022
781c1b0
fix(compiler-core): Slots containing branches should not be stable
baiwusanyu-c Dec 7, 2022
4166e3c
Merge branch 'main' into bwsy/fix/slot
baiwusanyu-c Dec 7, 2022
361531c
fix(compiler-core): update
baiwusanyu-c Dec 7, 2022
01a966d
fix(compiler-core): update unit test
baiwusanyu-c Dec 7, 2022
1fc0952
Merge branch 'vuejs:main' into bwsy/fix/slot
baiwusanyu-c Dec 7, 2022
53048f6
Merge branch 'vuejs:main' into bwsy/fix/slot
baiwusanyu-c Dec 26, 2022
2633e07
Merge branch 'vuejs:main' into bwsy/fix/slot
baiwusanyu-c Jan 2, 2023
89828f2
Merge branch 'vuejs:main' into bwsy/fix/slot
baiwusanyu-c Jan 9, 2023
9b71d4a
Merge branch 'vuejs:main' into bwsy/fix/slot
baiwusanyu-c Jan 14, 2023
1125a5e
Merge branch 'vuejs:main' into bwsy/fix/slot
baiwusanyu-c Feb 4, 2023
dd01f39
Merge branch 'vuejs:main' into bwsy/fix/slot
baiwusanyu-c Feb 6, 2023
849bf9c
Merge branch 'main' into bwsy/fix/slot
baiwusanyu-c Feb 14, 2023
a2474a9
Merge branch 'main' into bwsy/fix/slot
baiwusanyu-c Feb 21, 2023
7634fa9
Merge branch 'main' into bwsy/fix/slot
baiwusanyu-c Feb 22, 2023
d3b547a
Merge branch 'main' into bwsy/fix/slot
baiwusanyu-c Mar 17, 2023
7bbf658
Merge branch 'main' into bwsy/fix/slot
baiwusanyu-c Mar 20, 2023
439cf72
Merge branch 'main' into bwsy/fix/slot
baiwusanyu-c Mar 23, 2023
87bb8b7
Merge branch 'main' into bwsy/fix/slot
baiwusanyu-c Mar 27, 2023
ffcd196
Merge branch 'main' into bwsy/fix/slot
baiwusanyu-c Apr 6, 2023
4fe3eb8
Merge branch 'main' into bwsy/fix/slot
baiwusanyu-c Apr 10, 2023
1122f78
Merge branch 'main' into bwsy/fix/slot
baiwusanyu-c Apr 11, 2023
d8d36d4
Merge branch 'main' into bwsy/fix/slot
baiwusanyu-c Apr 14, 2023
4ed8fe6
Merge branch 'main' into bwsy/fix/slot
baiwusanyu-c Apr 17, 2023
64e9d96
Merge branch 'main' into bwsy/fix/slot
baiwusanyu-c Apr 19, 2023
5590742
Merge branch 'main' into bwsy/fix/slot
baiwusanyu-c Apr 20, 2023
3cb2b16
Merge branch 'main' into bwsy/fix/slot
baiwusanyu-c May 4, 2023
b60d209
Merge branch 'main' into bwsy/fix/slot
baiwusanyu-c May 16, 2023
54fe0c5
Merge remote-tracking branch 'origin/main' into bwsy/fix/slot
baiwusanyu-c Jun 27, 2023
f07776e
Merge branch 'main' into bwsy/fix/slot
baiwusanyu-c Sep 28, 2023
4cfe776
Merge remote-tracking branch 'origin/main' into bwsy/fix/slot
baiwusanyu-c Jan 3, 2024
25eea66
[autofix.ci] apply automated fixes
autofix-ci[bot] Jan 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions packages/compiler-core/src/transforms/vSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,24 +389,32 @@ function buildDynamicSlot(
return createObjectExpression(props)
}

function hasForwardedSlots(children: TemplateChildNode[]): boolean {
function hasForwardedSlots(
children: TemplateChildNode[],
hasBranches = false
): boolean {
for (let i = 0; i < children.length; i++) {
const child = children[i]
switch (child.type) {
case NodeTypes.ELEMENT:
if (
child.tagType === ElementTypes.SLOT ||
hasForwardedSlots(child.children)
(child.tagType === ElementTypes.ELEMENT && hasBranches) ||
hasForwardedSlots(child.children, hasBranches)
) {
return true
}
break
case NodeTypes.IF:
if (hasForwardedSlots(child.branches)) return true
hasBranches = true
if (hasForwardedSlots(child.branches, hasBranches)) return true
break
case NodeTypes.IF_BRANCH:
hasBranches = true
if (hasForwardedSlots(child.children, hasBranches)) return true
break
case NodeTypes.FOR:
if (hasForwardedSlots(child.children)) return true
if (hasForwardedSlots(child.children, hasBranches)) return true
break
default:
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ return function render(_ctx, _cache) {
], 2112 /* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */))
]))
]),
_: 1 /* STABLE */
_: 3 /* FORWARDED */
}))
}
}"
Expand Down
6 changes: 3 additions & 3 deletions packages/compiler-ssr/__tests__/ssrComponent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ describe('ssr: components', () => {
]
}
}),
_: 1 /* STABLE */
_: 3 /* FORWARDED */
}, _parent))
}"
`)
Expand Down Expand Up @@ -341,12 +341,12 @@ describe('ssr: components', () => {
? (_openBlock(), _createBlock("div", { key: 0 }))
: _createCommentVNode("v-if", true)
]),
_: 1 /* STABLE */
_: 3 /* FORWARDED */
})
]
}
}),
_: 1 /* STABLE */
_: 3 /* FORWARDED */
}, _parent))
}"
`)
Expand Down
59 changes: 58 additions & 1 deletion packages/runtime-core/__tests__/rendererOptimizedMode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {
createApp,
FunctionalComponent,
renderList,
onUnmounted
onUnmounted,
createElementBlock
} from '@vue/runtime-test'
import { PatchFlags, SlotFlags } from '@vue/shared'
import { SuspenseImpl } from '../src/components/Suspense'
Expand Down Expand Up @@ -933,4 +934,60 @@ describe('renderer: optimized mode', () => {
// should successfully unmount without error
expect(inner(root)).toBe(`<!---->`)
})

// #7256
test('When both the old and new dynamic node arrays are empty, turn off optimization and fully diff', async () => {
const show = ref(false)

const Child = {
setup(props: any, { slots }: SetupContext) {
return () => {
return renderSlot(slots, 'default', {}, () => [
!show.value
? (openBlock(),
createElementBlock('div', { key: 0 }, 'Fallback Content'))
: createCommentVNode('v-if', true)
])
}
}
}

const Parent = {
setup() {
return () => {
return (
openBlock(),
createBlock(Child, null, {
default: withCtx(() => [
show.value
? (openBlock(),
createElementBlock('div', { key: 0 }, 'Provided Content'))
: createCommentVNode('v-if', true)
]),
_: 3 /* FORWARDED */
})
)
}
}
}

const app = createApp({
setup() {
return () => {
return h(Parent)
}
}
})
app.mount(root)
await nextTick()
expect(inner(root)).toBe(`<div>Fallback Content</div>`)

show.value = true
await nextTick()
expect(inner(root)).toBe(`<div>Provided Content</div>`)

show.value = false
await nextTick()
expect(inner(root)).toBe(`<div>Fallback Content</div>`)
})
})
2 changes: 1 addition & 1 deletion packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ function baseCreateRenderer(
}

const areChildrenSVG = isSVG && n2.type !== 'foreignObject'
if (dynamicChildren) {
if (dynamicChildren && dynamicChildren.length > 0) {
patchBlockChildren(
n1.dynamicChildren!,
dynamicChildren,
Expand Down