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
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

### Improvements

- Make sure `MockedProvider` is using the proper CJS/ESM bundle, when
- Make sure `MockedProvider` is using the proper CJS/ESM bundle, when
referencing `ApolloProvider`. <br/>
[@jure](https://github.com/jure) in [#3029](https://github.com/apollographql/react-apollo/pull/3029).
- Adjust the `ApolloContext` definition to play a bit more nicely with
- Adjust the `ApolloContext` definition to play a bit more nicely with
`React.createContext` types. <br/>
[@JoviDeCroock](https://github.com/JoviDeCroock) in [#3018](https://github.com/apollographql/react-apollo/pull/3018)
- The result of a mutation is now made available to the wrapped component,
- The result of a mutation is now made available to the wrapped component,
when using the `graphql` HOC. <br/>
[@andycarrell](https://github.com/andycarrell) in [#3008](https://github.com/apollographql/react-apollo/pull/3008)
[@andycarrell](https://github.com/andycarrell) in [#3008](https://github.com/apollographql/react-apollo/pull/3008)

### Bug Fixes

Expand All @@ -23,6 +23,11 @@
- Fix typescript error caused by `query` being mandatory in the `fetchMore`
signature. <br/>
[@HsuTing](https://github.com/HsuTing) in [#3065](https://github.com/apollographql/react-apollo/pull/3065)
- Fixes an issue that caused the `Query` component to get stuck in an always
loading state, caused by receiving an error (meaning subsequent valid
responses couldn't be handled). The `Query` component can now handle an
error in a response, then continue to handle a valid response afterwards. <br/>
[@hwillson](https://github.com/hwillson) in [#3107](https://github.com/apollographql/react-apollo/pull/3107)


## 2.5.6 (2019-05-22)
Expand Down
18 changes: 10 additions & 8 deletions src/Query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,8 @@ export default class Query<TData = any, TVariables = OperationVariables> extends
this.updateCurrentData();
},
error: error => {
if (!this.lastResult) {
// We only want to remove the old subscription, and start a new
// subscription, when an error was received and we don't have a
// previous result stored. This means either no previous result was
// received due to problems fetching data, or the previous result
// has been forcefully cleared out.
this.resubscribeToQuery();
}
this.resubscribeToQuery();
hwillson marked this conversation as resolved.
Show resolved Hide resolved

if (!error.hasOwnProperty('graphQLErrors')) throw error;
this.updateCurrentData();
},
Expand Down Expand Up @@ -510,6 +504,14 @@ export default class Query<TData = any, TVariables = OperationVariables> extends
};
}

// When the component is done rendering stored query errors, we'll
// remove those errors from the `ObservableQuery` query store, so they
// aren't re-displayed on subsequent (potentially error free)
// requests/responses.
setTimeout(() => {
this.queryObservable!.resetQueryStoreErrors();
});

data.client = this.client;
return data;
};
Expand Down