Queries for unmounted components getting called after calling a mutation and resetStore.
See original GitHub issueWe have an application built up on react-native, apollo and graphql. The application is a fintech app which contains a dashboard with list of portfolios, the user choose the portfolio, goes to payment page and can make payment after which he is redirected to dashboard.
We were looking to clear cache on login for handling multi user behavior. We tried implementing resetStore
. This works fine when only queries were involved i.e. for unmounted components the queries were not called on resetStore
. This was as according to https://github.com/apollographql/apollo-client/issues/1319 and the fix https://github.com/apollographql/react-apollo/pull/671.
When we placed the order (createOrderMutation) and then tried calling resetStore
; user got logged out; then we tried logging in from a different user. At this point few of the queries are called on resetStore(dashboard query, portfolioDetailQuery, paymentScreenQuery etc…). Ideally no queries should be called beyond dashboardQuery as that is the only component that is currently mounted.
Intended outcome:
Queries for unmounted components should not get called after calling a mutation and resetStore
Actual outcome:
Queries for unmounted components are getting called after calling a mutation and resetStore
How to reproduce the issue: We have 3 screens:-
- dashboard containing portfolios
- portfolio containing add money button
- payment screen
Scenario:-
- User chooses a portfolio he goes goes to portfolio Detail screen and then on pressing add money button he is redirected to payment screen.
- Payment screen redirects to payment gateway after which user is redirected to dashboard.
- On succesfull payment user is redirected to dashboard.
- User is logged out
- New user is logged in and
resetStore
is called -->unmounted components queries are called
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (5 by maintainers)
Top GitHub Comments
Hi @helfer I debugged this issue a little further by creating a new project itself and observed that it is not linked to mutations at all. Yeah that was bit of a surprise.
The actual issue is that the
react-native
navigator does not unmount the current component on pushing new component on top. It just adds to the stack. So I when i move from dashboard -> portfolio -> paymentScreen -> payment gateway -> paymentSuccess screen it keeps on adding to it. Now onPaymentSuccess
Ireplace
the route, but myDashboard
,Portfolio
andPaymentScreen
are still mounted asreplace
as just replaces the route on top of the navigator and previous routes are still mounted; and according to apollo active queries onresetStore
are fired on reset store.So instead of
replace
from navigator I tried usingreplaceTo
from navigator which resets the stack and unmounts all components. Now on callingresetStore
no active queries are present and it works fine.I will go ahead and close this issue for now. Thanks for your help 😃
It seems that
replaceTo
solved your problem, can you point me towards some info about it ?