question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Queries for unmounted components getting called after calling a mutation and resetStore.

See original GitHub issue

We 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:-

  1. dashboard containing portfolios
  2. portfolio containing add money button
  3. payment screen

Scenario:-

  1. User chooses a portfolio he goes goes to portfolio Detail screen and then on pressing add money button he is redirected to payment screen.
  2. Payment screen redirects to payment gateway after which user is redirected to dashboard.
  3. On succesfull payment user is redirected to dashboard.
  4. User is logged out
  5. New user is logged in and resetStore is called --> unmounted components queries are called

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jinxaccommented, Jun 13, 2017

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 on PaymentSuccess I replace the route, but my Dashboard, Portfolio and PaymentScreen are still mounted as replace as just replaces the route on top of the navigator and previous routes are still mounted; and according to apollo active queries on resetStore are fired on reset store.

So instead of replace from navigator I tried using replaceTo from navigator which resets the stack and unmounts all components. Now on calling resetStore no active queries are present and it works fine.

I will go ahead and close this issue for now. Thanks for your help 😃

0reactions
sabativicommented, Jun 22, 2017

It seems that replaceTo solved your problem, can you point me towards some info about it ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced topics on caching in Apollo Client
To accomplish this, call client.resetStore . This method is asynchronous, because it also refetches any of your active queries.
Read more >
Handling Errors with Apollo Client (React) - YouTube
In this video I talk about handling errors when running queries and mutations using Apollo Client in a React project.Table of contents:00:00 ...
Read more >
Can't perform a React state update on an unmounted ...
I made sure the query wasn't loading and is available in the data object. For retreiving my data, I have a dashboard component...
Read more >
GraphQL query causes "Can't perform a React state update on ...
The form submits and works but causes the "Can't perform a React state update on an unmounted component" memory leak error and asks...
Read more >
A comprehensive guide to GraphQL with Apollo Client in React
When, Why, and How to Use GraphQL with Apollo Client in React ... You can create a method in a component that will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found