Skip to content

Commit

Permalink
ObservableQuery and QueryInfo stays forever on skip:true (#7205)
Browse files Browse the repository at this point in the history
Fixes #7206.
  • Loading branch information
kamilkisiela committed Oct 22, 2020
1 parent ed7e8ee commit 4ee52b3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,8 @@ once, rather than every time you call fetchMore.`);
}

private tearDownQuery() {
if (this.isTornDown) return;

const { queryManager } = this;

if (this.reobserver) {
Expand Down
2 changes: 2 additions & 0 deletions src/react/data/QueryData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ export class QueryData<TData, TVariables> extends OperationData {
if (this.currentSubscription) {
this.currentSubscription.unsubscribe();
delete this.currentSubscription;
} else if (this.currentObservable && this.getOptions().skip) {
this.currentObservable["tearDownQuery"]();
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/react/hooks/__tests__/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,30 @@ describe('useQuery Hook', () => {
expect(renderCount).toBe(3);
}).then(resolve, reject);
});

it('should tear down the query if `skip` is `true`', () => {
const client = new ApolloClient({
link: new ApolloLink(),
cache: new InMemoryCache()
});

const Component = () => {
useQuery(CAR_QUERY, { skip: true });
return null;
};

const app = render(
<ApolloProvider client={client}>
<Component />
</ApolloProvider>
);

expect(client['queryManager']['queries'].size).toBe(1);

app.unmount();

expect(client['queryManager']['queries'].size).toBe(0);
});
});

describe('Previous data', () => {
Expand Down

0 comments on commit 4ee52b3

Please sign in to comment.