Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 82c1223

Browse files
committed
fix(transition-group): avoid invalid hooks on unkeyed interop children
1 parent 62cb2ce commit 82c1223

3 files changed

Lines changed: 44 additions & 3 deletions

File tree

‎packages-private/vapor-e2e-test/__tests__/transition-group.spec.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,20 @@ describe('vapor transition-group', () => {
746746
)
747747

748748
describe('interop', () => {
749+
test('unkeyed vdom component update', async () => {
750+
const btnSelector = '.unkeyed-vdom-component-update > button'
751+
const containerSelector = '.unkeyed-vdom-component-update > div'
752+
753+
expect(await html(containerSelector)).toBe(`<div><div>a</div></div>`)
754+
755+
await page().click(btnSelector)
756+
757+
await waitForInnerHTML(
758+
containerSelector,
759+
`<div><div>a</div></div><div class="test">b</div>`,
760+
)
761+
})
762+
749763
test('static keyed vdom component enter', async () => {
750764
const btnSelector = '.static-keyed-vdom-component-enter > button'
751765
const containerSelector = '.static-keyed-vdom-component-enter > div'
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script setup vapor>
2+
import { ref } from 'vue'
3+
import VdomComp from '../../components/VdomComp.vue'
4+
5+
const show = ref(false)
6+
const update = () => (show.value = true)
7+
</script>
8+
9+
<template>
10+
<div class="unkeyed-vdom-component-update">
11+
<button @click="update">update button</button>
12+
<div>
13+
<transition-group name="test">
14+
<VdomComp>
15+
<div>a</div>
16+
</VdomComp>
17+
<div v-if="show" key="b" class="test">b</div>
18+
</transition-group>
19+
</div>
20+
</div>
21+
</template>

‎packages/runtime-vapor/src/components/TransitionGroup.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
type DefineVaporComponent,
4242
defineVaporComponent,
4343
} from '../apiDefineComponent'
44+
import { isInteropEnabled } from '../vdomInteropState'
4445

4546
const positionMap = new WeakMap<TransitionBlock, DOMRect>()
4647
const newPositionMap = new WeakMap<TransitionBlock, DOMRect>()
@@ -88,7 +89,7 @@ const VaporTransitionGroupImpl = defineVaporComponent({
8889
const children = getTransitionBlocks(slottedBlock)
8990
for (let i = 0; i < children.length; i++) {
9091
const child = children[i]
91-
if (isValidTransitionBlock(child)) {
92+
if (isValidTransitionBlock(child) && child.$transition) {
9293
prevChildren.push(child)
9394
// disabled transition during enter, so the children will be
9495
// inserted into the correct position immediately. this prevents
@@ -199,8 +200,13 @@ function applyGroupTransitionHooks(
199200
child,
200201
resolveTransitionHooks(child, props, state, instance),
201202
)
202-
} else if (__DEV__) {
203-
warn(`<transition-group> children must be keyed`)
203+
} else {
204+
if (isInteropEnabled && isFragment(child) && child.vnode) {
205+
child.$transition = undefined
206+
}
207+
if (__DEV__) {
208+
warn(`<transition-group> children must be keyed`)
209+
}
204210
}
205211
}
206212
}

0 commit comments

Comments
 (0)