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

Commit

Permalink
fix: Set networkStatus to be ready at the end of pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Injung Chung committed Sep 30, 2019
1 parent b07971e commit 732d430
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
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: 8 additions & 24 deletions packages/hooks/src/data/QueryData.ts
Expand Up @@ -267,30 +267,14 @@ export class QueryData<TData, TVariables> 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();
Expand Down

0 comments on commit 732d430

Please sign in to comment.