-
Notifications
You must be signed in to change notification settings - Fork 786
Query stuck in loading state when rendered after a query or a network error #3090
Comments
React Apollo relies on the `ObervableQuery->getCurrentResult` method to retrieve query results to show within its components. When an error occurs while fetching results, that error is stored in the query store that each `ObservableQuery` instance is configured to use. Unfortunately, `getCurrentResult` will only retrieve subsequent results if no error exists in the query store. `ObservableQuery` doesn't currently provide a way to clear out query store errors, which means when React Apollo originating requests that cause an error occur, the error is stored, and future valid requests can no longer be processed. This commit adds a `resetQueryStoreErrors` method to the `ObservableQuery` public API, that will allow React Apollo (and other consumers) to be able to clear out query store errors. Related to: apollographql/react-apollo#3090
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
We're just waiting on related Apollo Client changes, then we can get the fix for this (#3107) merged in. This will be included in the next RA release (actually, we're holding up the next release until this issue is resolved). |
…4941) * Reset query store errors via `ObservableQuery.resetQueryStoreErrors` React Apollo relies on the `ObervableQuery->getCurrentResult` method to retrieve query results to show within its components. When an error occurs while fetching results, that error is stored in the query store that each `ObservableQuery` instance is configured to use. Unfortunately, `getCurrentResult` will only retrieve subsequent results if no error exists in the query store. `ObservableQuery` doesn't currently provide a way to clear out query store errors, which means when React Apollo originating requests that cause an error occur, the error is stored, and future valid requests can no longer be processed. This commit adds a `resetQueryStoreErrors` method to the `ObservableQuery` public API, that will allow React Apollo (and other consumers) to be able to clear out query store errors. Related to: apollographql/react-apollo#3090 * Changelog update * Remove unnecessary expect
* Fix always loading issue caused by error handling 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 * Changelog update * Update deps to use new `apollo-client` 2.6.3
To fix issue #3090, the `ObservableQuery.resetQueryStoreErrors` method was introduced in `apollo-client` 2.6.3. While `apollo-client` 2.6.3 is a peer dep of the latest version of `react-apollo` (2.5.7), people who can't update their version of `apollo-client` to >= 2.6.3 are running into issues when updating to the latest version of `react-apollo`, since `ObservableQuery.resetQueryStoreErrors` isn't available to them. Since we can't enforce the version of `apollo-client` people are using, this commit adjusts the `Query` component to only use `resetQueryStoreErrors` if it's available. If it isn't, it will call into the `ObservableQuery`'s private API to do the same things as `resetQueryStoreErrors`. This is a hack, but it is temporary as `react-apollo` is launching soon, and will enforce a minimum `apollo-client` version of 2.6.3 (so this workaround won't be needed). Fixes #3148.
* Conditionally use AC's `ObservableQuery.resetQueryStoreErrors` To fix issue #3090, the `ObservableQuery.resetQueryStoreErrors` method was introduced in `apollo-client` 2.6.3. While `apollo-client` 2.6.3 is a peer dep of the latest version of `react-apollo` (2.5.7), people who can't update their version of `apollo-client` to >= 2.6.3 are running into issues when updating to the latest version of `react-apollo`, since `ObservableQuery.resetQueryStoreErrors` isn't available to them. Since we can't enforce the version of `apollo-client` people are using, this commit adjusts the `Query` component to only use `resetQueryStoreErrors` if it's available. If it isn't, it will call into the `ObservableQuery`'s private API to do the same things as `resetQueryStoreErrors`. This is a hack, but it is temporary as `react-apollo` is launching soon, and will enforce a minimum `apollo-client` version of 2.6.3 (so this workaround won't be needed). Fixes #3148. * Changelog update
It looks like this issue has been merged, but I still consistently get this error. I am using the Here are my dependencies:
I am working on a login form. So far I am having two issues.
|
Description
When a
<Query>
component which has previously resulted in a qraphQL or network error is re-rendered, its state changes from error to loading and no request is executed. The component is now stuck in loading state.Intended outcome:
If the query variables do not change, the
<Query>
stay in error state. Else the state change to loading and a new request is executed (cache or network).Actual outcome:
The
<Query>
component's state changes to loading and no request is executed, whatever the query's variables change or not.How to reproduce the issue:
I made a sample project to demonstrate the issue at https://codesandbox.io/s/apolloquerystuckaftererror-heyxu
==>
<Query>
stuck in loading stateVersion
The text was updated successfully, but these errors were encountered: