Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Fix always loading issue caused by error handling #3107

Merged
merged 5 commits into from
Jun 18, 2019
Merged

Conversation

hwillson
Copy link
Member

The React Apollo Query component relies on Apollo Client's ObservableQuery->getCurrentResult method to get the results of a query to display. When ObservableQuery encounters an error, it stores that error in its associated query store, so that it can be passed back to React Apollo for handling. Unfortunately, the error stored in the query store isn't cleared out until a component unmounts, which means components that handle an error response followed by a valid response, won't get the chance to render the valid response. They're stuck rendering the error state, since the error stored in the ObservableQuery query store is never removed.

This commit calls into a new ObservableQuery.resetQueryStoreErrors method, to clear out previously used errors, before moving on to handle subsequent responses. This means a component can handle an error, then receive and display a valid subsequent response.

Fixes: #3090

Note: This PR is dependent on apollographql/apollo-client#4941 being merged.

hwillson added 2 commits June 10, 2019 15:02
The React Apollo `Query` component relies on Apollo Client's
`ObservableQuery->getCurrentResult` method to get the results
of a query to display. When `ObservableQuery` encounters an
error, it stores that error in its associated query store, so
that it can be passed back to React Apollo for handling.
Unfortunately, the error stored in the query store isn't
cleared out until a component unmounts, which means components
that handle an error response followed by a valid response,
won't get the chance to render the valid response. They're
stuck rendering the error state, since the error stored in
the `ObservableQuery` query store is never removed.

This commit calls into a new
`ObservableQuery.resetQueryStoreErrors` method, to clear out
previously used errors, before moving on to handle subsequent
responses. This means a component can handle an error, then
receive and display a valid subsequent response.

Fixes: #3090
src/Query.tsx Show resolved Hide resolved
@hwillson hwillson marked this pull request as ready for review June 18, 2019 10:38
@hwillson hwillson merged commit a1e0b6d into master Jun 18, 2019
@hwillson hwillson deleted the hwillson/issue-3090 branch June 18, 2019 10:39
@jasonpaulos
Copy link
Contributor

@hwillson Any plans to bring this fix to RA 3 as well? Always resubscribing after an error fixes #2070 as well.

@hwillson
Copy link
Member Author

@jasonpaulos Definitely! I have it ready (I just haven't committed it yet). I should have it in the RA 3 branch shortly. As soon as it's there, I'm then planning on publishing a final version of RA 2, then will merge the RA 3 branch into master. So🤞by tomorrow morning we should be working against only one codebase again (yay! 🙂). Thanks!

@sambaek
Copy link

sambaek commented Jun 21, 2019

any updates on when the final version of RA 2 will be published with this fix?

hwillson added a commit that referenced this pull request Jun 21, 2019
@jasonpaulos
Copy link
Contributor

@sambaek I believe it was just published as 2.5.7

@developdeez
Copy link

developdeez commented Jul 31, 2019

I was using 2.5.6 and it was getting stuck.
I upgraded to 2.5.8 now it blinks several times before showing the page.

Im using a Query in my HOC to reject the user to the login if not logged in. Now it seems to make several repeated calls to the API for checking.

What gives?

<Query query={GET_CURRENT_USER} fetchPolicy="network-only" errorPolicy="none" >

@jasonpaulos
Copy link
Contributor

Hi @developdeez, could you create a new issue with this bug? It would also help a lot if you could provide a runnable reproduction that shows this. Thanks.

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

Successfully merging this pull request may close these issues.

Query stuck in loading state when rendered after a query or a network error
4 participants