Skip to content

Commit

Permalink
fix(TransitionGroup): not warn unkeyed text children with whitespece …
Browse files Browse the repository at this point in the history
…preserve (#11888)

close #11885
  • Loading branch information
edison1105 committed Sep 13, 2024
1 parent 8ea5d6d commit 7571f20
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/runtime-dom/src/components/TransitionGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
DeprecationTypes,
Fragment,
type SetupContext,
Text,
type VNode,
compatUtils,
createVNode,
Expand Down Expand Up @@ -159,7 +160,7 @@ const TransitionGroupImpl: ComponentOptions = /*@__PURE__*/ decorate({
child,
resolveTransitionHooks(child, cssTransitionProps, state, instance),
)
} else if (__DEV__) {
} else if (__DEV__ && child.type !== Text) {
warn(`<TransitionGroup> children must be keyed.`)
}
}
Expand Down
15 changes: 15 additions & 0 deletions packages/vue/__tests__/e2e/TransitionGroup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,21 @@ describe('e2e: TransitionGroup', () => {
expect(`<TransitionGroup> children must be keyed`).toHaveBeenWarned()
})

test('not warn unkeyed text children w/ whitespace preserve', () => {
const app = createApp({
template: `
<transition-group name="test">
<p key="1">1</p>
<p key="2" v-if="false">2</p>
</transition-group>
`,
})

app.config.compilerOptions.whitespace = 'preserve'
app.mount(document.createElement('div'))
expect(`<TransitionGroup> children must be keyed`).not.toHaveBeenWarned()
})

// #5168, #7898, #9067
test(
'avoid set transition hooks for comment node',
Expand Down

0 comments on commit 7571f20

Please sign in to comment.