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

Fix: removeQuery not removing a fetch's reject fn, mistakenly triggering "store reset when query in flight" error when store resets #4409

Merged

Conversation

cheapsteak
Copy link
Member

removeQuery was previously only calling unsubscribe on an operation's subscription, which doesn't trigger the error or complete handlers, thus the promise's reject function is not cleaned up (removed from fetchQueryRejectFns)

This PR changes fetchQueryRejectFns into a Map, and modifies removeQuery to delete an operation's associated reject fns from that map

Confirmed to have fixed the repo in #3555 (cloned it and linked a local apollo-client to the project)

Should also fix #3766 (although don't have a repro that exactly matches the submitted bug flow), possibly #2919

Might not fix #3792 (it sounds like another cleanup besides removing from fetchQueryRejectFns needs to happen)

Copy link
Member

@benjamn benjamn left a comment

Choose a reason for hiding this comment

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

Looking good, just a couple comments to update!

@@ -1088,12 +1091,10 @@ export class QueryManager<TStore> {
let resultFromStore: any;
let errorsFromStore: any;

let rejectFetchPromise: (reason?: any) => void;

return new Promise<ApolloQueryResult<T>>((resolve, reject) => {
// Need to assign the reject function to the rejectFetchPromise variable
// in the outer scope so that we can refer to it in the .catch handler.
Copy link
Member

Choose a reason for hiding this comment

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

You can remove this comment now (yay).

@cheapsteak cheapsteak force-pushed the chang/fix/store-reset-while-query-in-flight-map-rejectFns branch 3 times, most recently from 8942220 to 5e7d501 Compare February 4, 2019 21:25
@cheapsteak cheapsteak force-pushed the chang/fix/store-reset-while-query-in-flight-map-rejectFns branch from 5e7d501 to 6d27d05 Compare February 4, 2019 21:28
@cheapsteak
Copy link
Member Author

@benjamn updated and ready for re-review 🙏

@benjamn benjamn merged commit 17cbf64 into master Feb 4, 2019
@benjamn benjamn deleted the chang/fix/store-reset-while-query-in-flight-map-rejectFns branch February 4, 2019 21:54
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants