Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using a component containing a top level v-if in parent with $refs #6641

Closed
TomKaltz opened this issue Sep 19, 2017 · 6 comments
Closed

using a component containing a top level v-if in parent with $refs #6641

TomKaltz opened this issue Sep 19, 2017 · 6 comments

Comments

@TomKaltz
Copy link

Version

2.4.4

Reproduction link

https://jsfiddle.net/TomKaltz/aao0waem/

Steps to reproduce

Define a component where the top level element has a v-if. Declare that component in the parent template with a ref.

What is expected?

The ref should be available even if the component top-level v-if is false

What is actually happening?

Even if the v-if is false, the component is still accessible via $refs on first load. When you toggle the component v-if from false to true to false the parent ref becomes undefined. The component beforeDestroy and destroyed event also does not fire.

@TomKaltz TomKaltz changed the title using a component with top level v-if in parent with $refs using a component containing a top level v-if in parent with $refs Sep 19, 2017
@TomKaltz
Copy link
Author

This is related to #6632. Is this a bug or just some unintended feature that the ref is available on first render? This behavior seems to have only come up in the recent release.

@TomKaltz
Copy link
Author

TomKaltz commented Sep 19, 2017

The workaround of using a top level buffer div seems super hacky but does solve the problem.

@posva
Copy link
Member

posva commented Sep 19, 2017

To me this is working as expected. Also, you need a root element, so putting v-if in the root element of your component is probably giving you a warning or error on the console. However you can use a v-show instead so there's always a root element for the component

@TomKaltz
Copy link
Author

TomKaltz commented Sep 19, 2017 via email

@sgehrman
Copy link

sgehrman commented Oct 3, 2017

I'm having the same problem

@TomKaltz
Copy link
Author

TomKaltz commented Oct 3, 2017

Someone submitted pull request #6718 a few days ago. Hopefully it has a satisfactory fix for the issue. Looking forward to it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants