Skip to content

Commit 7571f20

Browse files
authoredSep 13, 2024··
fix(TransitionGroup): not warn unkeyed text children with whitespece preserve (#11888)
close #11885
1 parent 8ea5d6d commit 7571f20

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
 

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
DeprecationTypes,
1515
Fragment,
1616
type SetupContext,
17+
Text,
1718
type VNode,
1819
compatUtils,
1920
createVNode,
@@ -159,7 +160,7 @@ const TransitionGroupImpl: ComponentOptions = /*@__PURE__*/ decorate({
159160
child,
160161
resolveTransitionHooks(child, cssTransitionProps, state, instance),
161162
)
162-
} else if (__DEV__) {
163+
} else if (__DEV__ && child.type !== Text) {
163164
warn(`<TransitionGroup> children must be keyed.`)
164165
}
165166
}

‎packages/vue/__tests__/e2e/TransitionGroup.spec.ts

+15
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,21 @@ describe('e2e: TransitionGroup', () => {
509509
expect(`<TransitionGroup> children must be keyed`).toHaveBeenWarned()
510510
})
511511

512+
test('not warn unkeyed text children w/ whitespace preserve', () => {
513+
const app = createApp({
514+
template: `
515+
<transition-group name="test">
516+
<p key="1">1</p>
517+
<p key="2" v-if="false">2</p>
518+
</transition-group>
519+
`,
520+
})
521+
522+
app.config.compilerOptions.whitespace = 'preserve'
523+
app.mount(document.createElement('div'))
524+
expect(`<TransitionGroup> children must be keyed`).not.toHaveBeenWarned()
525+
})
526+
512527
// #5168, #7898, #9067
513528
test(
514529
'avoid set transition hooks for comment node',

0 commit comments

Comments
 (0)
Please sign in to comment.