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

Promises returned from dispatching manually initiated RTK queries doesn't handle in flight requests correctly #2186

Closed
wesen opened this issue Mar 31, 2022 · 0 comments
Milestone

Comments

@wesen
Copy link
Contributor

wesen commented Mar 31, 2022

The title is a bit long winded.

There is a long discussion in reactiflux' redux channel, starting around here.

Here is an example to reproduce the problem: bug-repro

The problem is when multiple queries are initiate()d, dispatch()d, and we then waited on, in quick succession.
Some promises will resolve "too" soon, and not wait on a previously initiated query that actually does a fetch.
The way to see this in the example posted above is clicking the button, and seeing the promises return a pending store state.

The problem is that only a single runningQuery is kept in the runningQueries cache to a query key in buildInitiate.ts.

I am running into this problem (which many other people probably don't) because I am replacing a legacy jquery app with rtk-query calls, and a lot of backend communication is done with async jquery.ajax call chains. As I was replacing these in the app (with forceRefetch: true or more refined invalidation mechanism), I realized that my await store.dispatch(api.endpoints.getCart.initiate()) promises were out of lockstep with the actual fetch() calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants