diff --git a/Changelog.md b/Changelog.md
index c48ada4037..557e0d97fe 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -1,5 +1,10 @@
# Change log
+## 3.1.3 (2019-10-15)
+
+- 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.
+ [@hwillson](https://github.com/hwillson) in [#TODO](https://github.com/apollographql/react-apollo/pull/TODO)
+
## 3.1.2 (2019-10-01)
### Bug Fixes
diff --git a/packages/hooks/src/__tests__/useLazyQuery.test.tsx b/packages/hooks/src/__tests__/useLazyQuery.test.tsx
index f9a1f39945..4b7062cef8 100644
--- a/packages/hooks/src/__tests__/useLazyQuery.test.tsx
+++ b/packages/hooks/src/__tests__/useLazyQuery.test.tsx
@@ -1,4 +1,4 @@
-import React, { useState } from 'react';
+import React from 'react';
import { DocumentNode } from 'graphql';
import gql from 'graphql-tag';
import { MockedProvider } from '@apollo/react-testing';
@@ -389,62 +389,4 @@ describe('useLazyQuery Hook', () => {
});
}
);
-
- it('should only call onCompleted once per query run', async () => {
- let renderCount = 0;
- let onCompletedCount = 0;
- const Component = () => {
- const [_, setCounter] = useState(0);
- const [execute, { loading, data }] = useLazyQuery(CAR_QUERY, {
- onCompleted() {
- onCompletedCount += 1;
- }
- });
-
- switch (renderCount) {
- case 0:
- expect(loading).toEqual(false);
- setTimeout(() => {
- execute();
- });
- break;
- case 1:
- expect(loading).toEqual(true);
- break;
- case 2:
- expect(loading).toEqual(false);
- expect(data).toEqual(CAR_RESULT_DATA);
- setTimeout(() => {
- execute({ variables: { someProp: 'someValue' } });
- });
- break;
- case 3:
- expect(loading).toEqual(false);
- expect(data).toEqual(CAR_RESULT_DATA);
- // Force a render to help make sure onCompleted isn't called again
- // since the query isn't re-run.
- setCounter(1);
- break;
- case 4:
- expect(loading).toEqual(false);
- expect(data).toEqual(CAR_RESULT_DATA);
- break;
- default: // Do nothing
- }
-
- renderCount += 1;
- return null;
- };
-
- render(
-
-
-
- );
-
- await wait(() => {
- expect(onCompletedCount).toBe(2);
- expect(renderCount).toBe(5);
- });
- });
});
diff --git a/packages/hooks/src/utils/useBaseQuery.ts b/packages/hooks/src/utils/useBaseQuery.ts
index 8519a540b0..18922e90be 100644
--- a/packages/hooks/src/utils/useBaseQuery.ts
+++ b/packages/hooks/src/utils/useBaseQuery.ts
@@ -51,17 +51,12 @@ export function useBaseQuery(
? (result as QueryTuple)[1]
: (result as QueryResult);
- useEffect(
- () => queryData.afterExecute({ lazy }),
- lazy
- ? undefined
- : [
- queryResult.loading,
- queryResult.networkStatus,
- queryResult.error,
- queryResult.data
- ]
- );
+ useEffect(() => queryData.afterExecute({ lazy }), [
+ queryResult.loading,
+ queryResult.networkStatus,
+ queryResult.error,
+ queryResult.data
+ ]);
useEffect(() => {
return () => queryData.cleanup();