From d14cf0eeed08c783940ea78f3f13312e3ce25703 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Fri, 30 Oct 2020 16:28:30 -0400 Subject: [PATCH] Call this.currentObservable.tearDownQuery more consistently (#7259) Follow-up to #7205, per my comment in #7254: https://github.com/apollographql/apollo-client/issues/7254#issuecomment-718977276 Instead of tearing down this.currentObservable only when this.getOptions().skip is true in QueryData#removeQuerySubscription, I split the tear-down functionality into a separate private method (QueryData#removeObservable), which is now called everywhere removeQuerySubscription is called, except in resubscribeToQuery, where we specifically want to preserve this.observableQuery. --- src/react/data/QueryData.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/react/data/QueryData.ts b/src/react/data/QueryData.ts index 333e6e82305..7ae527df065 100644 --- a/src/react/data/QueryData.ts +++ b/src/react/data/QueryData.ts @@ -63,6 +63,7 @@ export class QueryData extends OperationData { const { skip, query } = this.getOptions(); if (skip || query !== this.previous.query) { this.removeQuerySubscription(); + this.removeObservable(!skip); this.previous.query = query; } @@ -107,7 +108,7 @@ export class QueryData extends OperationData { public cleanup() { this.removeQuerySubscription(); - delete this.currentObservable; + this.removeObservable(true); delete this.previous.result; } @@ -471,8 +472,15 @@ export class QueryData extends OperationData { if (this.currentSubscription) { this.currentSubscription.unsubscribe(); delete this.currentSubscription; - } else if (this.currentObservable && this.getOptions().skip) { + } + } + + private removeObservable(andDelete: boolean) { + if (this.currentObservable) { this.currentObservable["tearDownQuery"](); + if (andDelete) { + delete this.currentObservable; + } } }