fix(TransitionGroup): not warn unkeyed text children with whitespece preserve (#11888)

close #11885
This commit is contained in:
edison 2024-09-13 18:37:42 +08:00 committed by GitHub
parent 8ea5d6d698
commit 7571f20bc3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View File

@ -14,6 +14,7 @@ import {
DeprecationTypes,
Fragment,
type SetupContext,
Text,
type VNode,
compatUtils,
createVNode,
@ -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.`)
}
}

View File

@ -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',