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(useIsFetching): account for fetches happening in the same render cycle #3438

Merged

Conversation

TkDodo
Copy link
Collaborator

@TkDodo TkDodo commented Mar 24, 2022

fixes #3437

if a fetch happens in the same render cycle as useIsFetching is mounting, but it is mounted after the query, what happens is that:

  • the initial state of isFetching is 0 because the effect to fetch the query hasn't started yet
  • the query effect runs before the isFetching effect, which means we miss the event, thus the next event we get from the subscription gives us 0 again

so we need to check for isFetching in the effect that runs to set up the subscription as well. This catches fetches that basically started in the same effect cycle, but before "our" effect ran

…cycle

if a fetch happens in the same render cycle as useIsFetching is mounting, but it is mounted after the query, what happens is that:

- the initial state of `isFetching` is `0` because the effect to fetch the query hasn't started yet
- the query effect runs before the isFetching effect, which means we miss the event, thus the next event we get from the subscription gives us 0 again

so we need to check for isFetching in the effect that runs to set up the subscription as well. This catches fetches that basically started in the same effect cycle, but before "our" effect ran
@vercel
Copy link

vercel bot commented Mar 24, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/tanstack/react-query/CuSyeik8Wo4TJcrkBRnoixhoSkdi
✅ Preview: https://react-query-git-fork-tkdodo-feature-3437-useisf-efe9b5-tanstack.vercel.app

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 86df754:

Sandbox Source
tannerlinsley/react-query: basic Configuration
tannerlinsley/react-query: basic-typescript Configuration

@codecov
Copy link

codecov bot commented Mar 24, 2022

Codecov Report

Merging #3438 (86df754) into master (ce61a2a) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #3438   +/-   ##
=======================================
  Coverage   96.40%   96.40%           
=======================================
  Files          45       45           
  Lines        2278     2282    +4     
  Branches      641      641           
=======================================
+ Hits         2196     2200    +4     
  Misses         79       79           
  Partials        3        3           
Impacted Files Coverage Δ
src/react/useIsFetching.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ce61a2a...86df754. Read the comment docs.

@TkDodo TkDodo merged commit 31bcaf1 into TanStack:master Mar 24, 2022
@TkDodo TkDodo deleted the feature/3437-useIsFetching-always-returns-false branch March 24, 2022 19:33
@tannerlinsley
Copy link
Collaborator

🎉 This PR is included in version 3.34.17 🎉

The release is available on:

Your semantic-release bot 📦🚀

@tannerlinsley
Copy link
Collaborator

🎉 This PR is included in version 4.0.0-alpha.22 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

useIsFetching always returns false
2 participants