Subscribe on changes!

Unable to get current instance after rendering another component in setup

avatar
Nov 4th 2022

Vue version

3.2.41

Link to minimal reproduction

https://codesandbox.io/s/tender-carson-78f4nw

Steps to reproduce

Run the minimal reproduction, then observe the console, there is no app mounted, also the judgment of the instance is also print false

What is expected?

app mounted called, and get the instance anywhere in the setup

What is actually happening?

lost my component instance after another component rendered

System Info

no

Any additional comments?

no

avatar
Nov 4th 2022

I don't think this is a good idea, you should use a Teleport component instead. Is there anything blocking you from using Teleport?

avatar
Nov 5th 2022

Teleport component is not only a declarative component, but also I can't make it singleton. In many ui frameworks there are components rendered by functional calls, such as Notification. I don't think Teleport component is suitable for every situations.

avatar
Nov 5th 2022

Note that the declarative approach is often the preferred way and that you could perfectly do the same you are doing with a Teleport component and an array of notifications

avatar
Nov 5th 2022

I understand, but this situation should also be covered and paid attention to, a large number of frameworks are also used in this way. Using an array to store the instance covers this situation perfectly and doesn't cost a lot, poping and pushing performance is very fast, I think fix this will make Vue3 more robust.