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

Commit 0901f4a

Browse files
committed
Revert the changes made in #3497
often than necessary. Fixes: #3505
1 parent 4163f28 commit 0901f4a

File tree

3 files changed

+12
-70
lines changed

3 files changed

+12
-70
lines changed

Changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change log
22

3+
## 3.1.3 (2019-10-15)
4+
5+
- Revert the changes made in [#3497](https://github.com/apollographql/react-apollo/pull/3497), which have lead to problems with `onCompleted` being called more often than necessary. <br/>
6+
[@hwillson](https://github.com/hwillson) in [#TODO](https://github.com/apollographql/react-apollo/pull/TODO)
7+
38
## 3.1.2 (2019-10-01)
49

510
### Bug Fixes

packages/hooks/src/__tests__/useLazyQuery.test.tsx

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React from 'react';
22
import { DocumentNode } from 'graphql';
33
import gql from 'graphql-tag';
44
import { MockedProvider } from '@apollo/react-testing';
@@ -389,62 +389,4 @@ describe('useLazyQuery Hook', () => {
389389
});
390390
}
391391
);
392-
393-
it('should only call onCompleted once per query run', async () => {
394-
let renderCount = 0;
395-
let onCompletedCount = 0;
396-
const Component = () => {
397-
const [_, setCounter] = useState(0);
398-
const [execute, { loading, data }] = useLazyQuery(CAR_QUERY, {
399-
onCompleted() {
400-
onCompletedCount += 1;
401-
}
402-
});
403-
404-
switch (renderCount) {
405-
case 0:
406-
expect(loading).toEqual(false);
407-
setTimeout(() => {
408-
execute();
409-
});
410-
break;
411-
case 1:
412-
expect(loading).toEqual(true);
413-
break;
414-
case 2:
415-
expect(loading).toEqual(false);
416-
expect(data).toEqual(CAR_RESULT_DATA);
417-
setTimeout(() => {
418-
execute({ variables: { someProp: 'someValue' } });
419-
});
420-
break;
421-
case 3:
422-
expect(loading).toEqual(false);
423-
expect(data).toEqual(CAR_RESULT_DATA);
424-
// Force a render to help make sure onCompleted isn't called again
425-
// since the query isn't re-run.
426-
setCounter(1);
427-
break;
428-
case 4:
429-
expect(loading).toEqual(false);
430-
expect(data).toEqual(CAR_RESULT_DATA);
431-
break;
432-
default: // Do nothing
433-
}
434-
435-
renderCount += 1;
436-
return null;
437-
};
438-
439-
render(
440-
<MockedProvider mocks={CAR_MOCKS}>
441-
<Component />
442-
</MockedProvider>
443-
);
444-
445-
await wait(() => {
446-
expect(onCompletedCount).toBe(2);
447-
expect(renderCount).toBe(5);
448-
});
449-
});
450392
});

packages/hooks/src/utils/useBaseQuery.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,12 @@ export function useBaseQuery<TData = any, TVariables = OperationVariables>(
5151
? (result as QueryTuple<TData, TVariables>)[1]
5252
: (result as QueryResult<TData, TVariables>);
5353

54-
useEffect(
55-
() => queryData.afterExecute({ lazy }),
56-
lazy
57-
? undefined
58-
: [
59-
queryResult.loading,
60-
queryResult.networkStatus,
61-
queryResult.error,
62-
queryResult.data
63-
]
64-
);
54+
useEffect(() => queryData.afterExecute({ lazy }), [
55+
queryResult.loading,
56+
queryResult.networkStatus,
57+
queryResult.error,
58+
queryResult.data
59+
]);
6560

6661
useEffect(() => {
6762
return () => queryData.cleanup();

0 commit comments

Comments
 (0)