-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(compiler-core): emit error on v-if key usage
- Loading branch information
Showing
4 changed files
with
23 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58b4a38
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change for me.
I have the following use-case:
I'm rendering details of an item.
When the item changes, I don't want the DOM to be updated in-place, rather I want the DOM to be fully removed and replaced by a fresh new DOM.
I achieve this by changing the
key
of the rendered item.On top of that, I want to render nothing when no item is selected, so there's a
if
on the same node.Something like that:
Out of curiosity, why is the key important to
v-if
?58b4a38
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be relevant for you #1712 (comment)
58b4a38
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@posva thanks it provides some context.
From that comment I get the impression that the issue is having 2 elements with the same key?
Shouldn't that be specifically targeted by the error?
Preventing
key
onv-if
restricts its usefulness and doesn't prevent other silly cases such as<div :key="1" /> <div :key="1" />
and others, possibly less silly and more unfortunate.In my specific case, is the recommended approach to wrap things in additional elements?
(Assuming it works, I haven't tested it)
58b4a38
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also use
key
withv-if
quite a bit with Vue 2. Specially I use it in conjunction with<transition>
when the root is not a component so I can be sure the entire element is animated when some state changes and not just patched in-place w/o a transition. What would be the suggestion in that case or does Vue 3 handle that seamlessly already?58b4a38
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See de0c8a7 - it's been fixed to only error on same key for different branches.
58b4a38
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yyx990803 great, thank you!