-
-
Notifications
You must be signed in to change notification settings - Fork 522
Description
Describe the bug
I was recently investigating a bug where various refetch calls for queries where not fetching data anymore after some time on the page. What I found is that queries are being stopped internally by Apollo through the onBeforeUnmount hook. While this might make sense on components, it can get troublesome on pinia stores where they are currently defined in my project. The hooks defined in a store are directed to the component the store is initialized on, and once that component is unmounted it also stops the query, even if it is still in use through the store. This might pose no problem if the store was initialized e.g. on the root component which never is unmounted, but is undesirable if initialized on any component that will unmount during the page's lifetime.
To Reproduce
Steps to reproduce the behavior:
- Create a pinia store and use
useQuery. - Initialize the pinia store (= call the
use[..]Storefor the first time) on a component that you can unmount through any means. - Unmount the component.
- Call
refetchfrom theuseQuerydefined in the store - it will returnundefined, thequeryobject fromuseQuerywill benull, and the data - if being changed - will not update.
Expected behavior
In pinia stores, queries should not be stopped internally at all, regardless of the component they were first initialized on.
Versions
vue: 3.4.20
vue-apollo: 4.0.1
@apollo/client: 3.9.5
Additional context
A workaround for this issue would be to initialize every store that uses useQuery on the root component to ensure that the onBeforeUnmount hook will never be called before the lifetime of the page ends.