$refs not reset when destroying element on event within watch
callback on prop value change
#12639
Labels
🔨 p3-minor-bug
Priority 3: this fixes a bug, but is an edge case that only affects very specific usage.
Vue version
5a6e98c, 3.5.13
Link to minimal reproduction
https://play.vuejs.org/#eNqNVE1zmzAQ/SuKpjO2Zxw4tCeK3TadHNpD3UkyvRQfKCygBCSNJIwzHv/3roQFthNn4gMWb3fffj2xo9+kDDYt0IjGBhpZpwaWCSckFqYCdZ2JRgoO3FiMkM01KxYJzZlGz+eE9qgCC7oAD0VCArcg/nnsa1YLDfkYTxakSGsNvUPY583Zxh3w+K81RnAbx7KnAxnGXPWkywdRljWsLDjd7Yiz7vezOOzjLrGMya+GPg5c95XoHJf3eQedVIybOyj0dIY8w9tJWBz6ruLwaMoJj3WmmDTOxHDSypCVHeN3P3ZSKNGQhAbhKW53ltDPlgO2Li6HIm1rQ3aWa1ibjnqAIMf5Rml0lmxuPffumacmnc58rALTKu7f0NqPJyJGteD87c8u4ATaj3yZAuw5Hyk7xnPRBVkjcRGmYhp78c4NmErkY+lHIx5ryATXooagFuV08gElqP8OGlxP5o4z6PGJgyfrmcvhs9gnVhiHww7onBqNvAUrg0ctOF4Kly6hdmisBrWShmFeO7phrGldi+6nw456x5gKsqdX8Ee9tVhCfyvQoDa4x8FmUlWC20xCb+9/wRbPg7EReVuj9xvGO8CZtLbG3u2m5TmWfeTnqv3hpMZ4+aBvtwa49k3ZQsc9JBRVZtVxqfWx3I/BJxeHI8UpvtTqy++LXJ56xaFEw8X78ZrKpRJyVEkvv0Ef5llCRG4EaiTlXpBHCoeG2duB4sA4yFExk/77NFk7e5earDohn3Lo/qR1C2cqNAQ29qouiHcgX4inJdHAe1AfluakaQuYusjZW7Kk+/9809vh
Steps to reproduce
this.$refs.other
': the instance of theother-component
.other-component
disappears andthis.$refs.other
is set tonull
.null
, butthis.$refs.other
contains theother-component
instance!What is expected?
Clicking on "ToggleOpen" sets the
open
reactive data tofalse
. This reactive data is bound to theopen
prop of theother-component
, who watches changes on that prop and emits an eventclosed
whenfalse
. The main component listens on the@closed
event and sets thedisplay
reactive data tofalse
when received. Thedisplay
reactive data is bound to thev-if
directive.I would expect that setting
display
tofalse
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
anddisplay
, and the watch callback does not know whether any listener of the@closed
event will try to destroy the instance. Additionally, the original code usesv-for
instead ofv-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.
The text was updated successfully, but these errors were encountered: