Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent unhandled rejections by stopping QueryManager more thoroughly. #4359

Merged
merged 1 commit into from
Jan 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions packages/apollo-client/src/core/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ export class QueryManager<TStore> {
*/
public stop() {
this.scheduler.stop();

this.queries.forEach((_info, queryId) => {
this.stopQueryNoBroadcast(queryId);
});

this.fetchQueryRejectFns.forEach(reject => {
reject(new Error('QueryManager stopped while query was in flight'));
});
Expand Down Expand Up @@ -721,9 +726,14 @@ export class QueryManager<TStore> {
}

public stopQueryInStore(queryId: string) {
this.stopQueryInStoreNoBroadcast(queryId);
this.broadcastQueries();
}

private stopQueryInStoreNoBroadcast(queryId: string) {
this.scheduler.stopPollingQuery(queryId);
this.queryStore.stopQuery(queryId);
this.invalidate(true, queryId);
this.broadcastQueries();
}

public addQueryListener(queryId: string, listener: QueryListener) {
Expand Down Expand Up @@ -953,7 +963,12 @@ export class QueryManager<TStore> {
}

public stopQuery(queryId: string) {
this.stopQueryInStore(queryId);
this.stopQueryNoBroadcast(queryId);
this.broadcastQueries();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reiterating #4337 (comment) here:

This now waits to call this.broadcastQueries() until after the query has been removed, whereas previously this.stopQueryInStore(queryId) would stop the query, call this.broadcastQueries(), then return control to stopQuery, which would finally call this.removeQuery(queryId).

It makes more sense to me to wait until the query has been removed to broadcast queries, but I'm not sure if this semantic subtlety was important before.

}

private stopQueryNoBroadcast(queryId: string) {
this.stopQueryInStoreNoBroadcast(queryId);
this.removeQuery(queryId);
}

Expand Down