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

Commit

Permalink
Fix an error that the networkStatus did not change to ready at the en…
Browse files Browse the repository at this point in the history
…d of pagination (#3514)

* fix: Set networkStatus to be ready at the end of pagination

* Changelog update
  • Loading branch information
Injung Chung authored and hwillson committed Oct 2, 2019
1 parent 9d8a4a0 commit 551e754
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 25 deletions.
4 changes: 3 additions & 1 deletion Changelog.md
Expand Up @@ -6,8 +6,10 @@

- Make sure SSR is fully disabled when using `ssr: false` and `ssrMode: true`. <br/>
[@maapteh](https://github.com/maapteh) in [#3515](https://github.com/apollographql/react-apollo/pull/3515)
- Fix `MockLink`'s broken `newData` function handling. <br/>
- Fixed `MockLink`'s broken `newData` function handling. <br/>
[@pawelkleczek](https://github.com/pawelkleczek) in [#3539](https://github.com/apollographql/react-apollo/pull/3539)
- Fixed an issue that prevented `networkStatus` from changing `ready` at the end of pagination. <br/>
[@mu29](https://github.com/mu29) in [#3514](https://github.com/apollographql/react-apollo/pull/3514)

## 3.1.1 (2019-09-15)

Expand Down
7 changes: 6 additions & 1 deletion packages/hooks/src/__tests__/useQuery.test.tsx
Expand Up @@ -841,6 +841,11 @@ describe('useQuery Hook', () => {
break;
case 3:
expect(loading).toBeFalsy();
expect(data).toEqual({
cars: [carResults.cars[0]]
});
break;
case 4:
expect(data).toEqual({
cars: [carResults.cars[0], moreCarResults.cars[0]]
});
Expand All @@ -859,7 +864,7 @@ describe('useQuery Hook', () => {
);

await wait(() => {
expect(renderCount).toBe(4);
expect(renderCount).toBe(5);
});
}
);
Expand Down
32 changes: 9 additions & 23 deletions packages/hooks/src/data/QueryData.ts
Expand Up @@ -268,29 +268,15 @@ export class QueryData<TData, TVariables> extends OperationData {
this.currentObservable.subscription = obsQuery.subscribe({
next: ({ loading, networkStatus, data }) => {
const previousResult = this.previousData.result;
if (previousResult) {
// Calls to `ObservableQuery.fetchMore` return a result before the
// `updateQuery` function fully finishes. This can lead to an
// extra un-necessary re-render since the initially returned data is
// the same as data that has already been rendered. We'll
// prevent the un-necessary render from happening, making sure
// `fetchMore` results are only rendered when `updateQuery` has
// completed.
if (
previousResult.loading &&
previousResult.networkStatus === NetworkStatus.fetchMore &&
isEqual(previousResult.data, data)
) {
return;
}
// Make sure we're not attempting to re-render similar results
if (
previousResult.loading === loading &&
previousResult.networkStatus === networkStatus &&
isEqual(previousResult.data, data)
) {
return;
}

// Make sure we're not attempting to re-render similar results
if (
previousResult &&
previousResult.loading === loading &&
previousResult.networkStatus === networkStatus &&
isEqual(previousResult.data, data)
) {
return;
}

this.forceUpdate();
Expand Down

0 comments on commit 551e754

Please sign in to comment.