-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Description
Vue version
5a6e98c, 3.5.13
Link to minimal reproduction
Steps to reproduce
- Open Web Developer Tools > Console.
- Click on "printRefs" button. This prints current value of
this.$refs.other': the instance of theother-component. - Click on "ToggleDisplay" and then on "printRefs" again. The
other-componentdisappears andthis.$refs.otheris set tonull. - Click on "ToggleDisplay" and "printRefs" again. State equivalent to 2.
- Click on "ToggleOpen", then on "printRefs". We expect
null, butthis.$refs.othercontains theother-componentinstance!
What is expected?
Clicking on "ToggleOpen" sets the open reactive data to false. This reactive data is bound to the open prop of the other-component, who watches changes on that prop and emits an event closed when false. The main component listens on the @closed event and sets the display reactive data to false when received. The display reactive data is bound to the v-if directive.
I would expect that setting display to false directly and indirectly (in the complicated sequence above) would lead to the same result: the component is unmounted, the instance destroyed and any $refs cleared.
What is actually happening?
$refs is not cleared and the instance is not destroyed.
System Info
No response
Any additional comments?
The above is a reduced example. As far as I could test the combination of prop -> watch -> emit -> v-if together with ref is needed to reproduce the issue.
In the context where the issue originally appeared there is not a linear dependency between open and display, and the watch callback does not know whether any listener of the @closed event will try to destroy the instance. Additionally, the original code uses v-for instead of v-if; in that case the $refs array seems to only grow and never shrink.
Please let me know whether something is unclear or more information is needed.
Thank you.