Skip to content

Commit

Permalink
Add React Apollo changes from PR #3514
Browse files Browse the repository at this point in the history
  • Loading branch information
hwillson committed Oct 2, 2019
1 parent bee8ee9 commit 5b24bbf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
32 changes: 8 additions & 24 deletions src/react/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
7 changes: 6 additions & 1 deletion src/react/hooks/__tests__/useQuery.test.tsx
Expand Up @@ -851,6 +851,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 @@ -869,7 +874,7 @@ describe('useQuery Hook', () => {
);

return wait(() => {
expect(renderCount).toBe(4);
expect(renderCount).toBe(5);
});
}
);
Expand Down

0 comments on commit 5b24bbf

Please sign in to comment.