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-dom): TransitionGroup children el may be null #9068

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion packages/runtime-dom/src/components/TransitionGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ const TransitionGroupImpl: ComponentOptions = {
tag = 'span'
}

prevChildren = children
prevChildren =
children &&
children.filter((c: VNode) => c.el && c.el.getBoundingClientRect)
children = slots.default ? getTransitionRawChildren(slots.default()) : []

for (let i = 0; i < children.length; i++) {
Expand Down
47 changes: 47 additions & 0 deletions packages/vue/__tests__/e2e/TransitionGroup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,4 +508,51 @@ describe('e2e: TransitionGroup', () => {

expect(`<TransitionGroup> children must be keyed`).toHaveBeenWarned()
})

test('TransitionGroup on child components with empty root node', async () => {
const pageTemp = await page()
pageTemp.evaluate(() => {
const { createApp, ref } = (window as any).Vue
createApp({
template: `
<div id="container">
<transition-group name="group">
<Comp v-for="item in items" :key="item"></Comp>
</transition-group>
</div>
<button id="toggleBtn" @click="click">button</button>
<button id="pushBtn" @click="change">button</button>
`,
components: {
Comp: {
template: '<div v-if="false">one</div>'
}
},
setup: () => {
const items = ref(['1', '2'])
const click = () => {
setTimeout(() => {
items.value.splice(0, 1)
})
}
const change = () => {
items.value.push('3')
}
return { items, click, change }
}
}).mount('#app')
})

expect(await html('#container')).toBe('<!--v-if--><!--v-if-->')
// splice
await htmlWhenTransitionStart()
await transitionFinish()
expect(await html('#container')).toBe(`<!--v-if-->`)
// push back
await page().evaluate(() => {
;(document.querySelector('#pushBtn') as any)!.click()
})
await transitionFinish()
expect(await html('#container')).toBe('<!--v-if--><!--v-if-->')
})
})
Loading