From 732d430c884ff747de4b2a6056832123e52cdab2 Mon Sep 17 00:00:00 2001 From: Injung Chung Date: Sat, 21 Sep 2019 13:48:55 +0900 Subject: [PATCH 1/2] fix: Set networkStatus to be ready at the end of pagination --- .../hooks/src/__tests__/useQuery.test.tsx | 7 +++- packages/hooks/src/data/QueryData.ts | 32 +++++-------------- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/packages/hooks/src/__tests__/useQuery.test.tsx b/packages/hooks/src/__tests__/useQuery.test.tsx index 6cbdb8e5a5..373dddef7c 100644 --- a/packages/hooks/src/__tests__/useQuery.test.tsx +++ b/packages/hooks/src/__tests__/useQuery.test.tsx @@ -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]] }); @@ -859,7 +864,7 @@ describe('useQuery Hook', () => { ); await wait(() => { - expect(renderCount).toBe(4); + expect(renderCount).toBe(5); }); } ); diff --git a/packages/hooks/src/data/QueryData.ts b/packages/hooks/src/data/QueryData.ts index 06efa6d0b1..a45b24258a 100644 --- a/packages/hooks/src/data/QueryData.ts +++ b/packages/hooks/src/data/QueryData.ts @@ -267,30 +267,14 @@ export class QueryData extends OperationData { 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(); From b29cd7cf7009dbe6a18c7459af592d9eafcab8e4 Mon Sep 17 00:00:00 2001 From: hwillson Date: Tue, 1 Oct 2019 20:40:27 -0400 Subject: [PATCH 2/2] Changelog update --- Changelog.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 35e9c683cd..c7da771eb5 100644 --- a/Changelog.md +++ b/Changelog.md @@ -6,8 +6,10 @@ - Make sure SSR is fully disabled when using `ssr: false` and `ssrMode: true`.
[@maapteh](https://github.com/maapteh) in [#3515](https://github.com/apollographql/react-apollo/pull/3515) -- Fix `MockLink`'s broken `newData` function handling.
+- Fixed `MockLink`'s broken `newData` function handling.
[@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.
+ [@mu29](https://github.com/mu29) in [#3514](https://github.com/apollographql/react-apollo/pull/3514) ## 3.1.1 (2019-09-15)