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

infiniteQuery continues to refetch data even if there are no more observers #1412

Closed
Khufu-I opened this issue Dec 14, 2020 · 4 comments · Fixed by #1761
Closed

infiniteQuery continues to refetch data even if there are no more observers #1412

Khufu-I opened this issue Dec 14, 2020 · 4 comments · Fixed by #1761
Labels
bug Something isn't working

Comments

@Khufu-I
Copy link

Khufu-I commented Dec 14, 2020

Describe the bug
infiniteQuery continues to iterate and fetch all pages even after there are no more observers to consume the data. If the infiniteQuery contains a large set of pages (i.e. 100) this causes unnecessary network load and keeps references to variables for a long time.

To Reproduce
Steps to reproduce the behavior:
Open sample in CodeSandbox

  1. Allow all pages to finish loading (up to 15 pages).
  2. Open Console tab (bottom right) in CodeSandbox or browser console
  3. Sample app will print Fetched page every time an API call is simulated
  4. Click on Toggle button to unmount the component which calls useInfiniteQuery
  5. Notice even though there are no more observers which consume the components query the infiniteQuery continues to fetch pages in the background.

Expected behavior
After all observers (i.e. React components) which consume an infiniteQuery go out of scope the infiniteQuery should stop fetching subsequent pages.

Screenshots
Screen Shot 2020-12-14 at 13 52 00

Desktop (please complete the following information):

  • OS: all
  • Browser: all
  • Version: all

Smartphone (please complete the following information):

  • Device: all
  • OS: all
  • Browser: all
  • Version: all

Additional context
Possible code that controls this behaviour

@jayakusumah
Copy link

same issue, I'm using nextjs and following the example

@GermaVinsmoke
Copy link

Gave a staleTime of 1000 * 60 * 60 but then also it's fetching

@Khufu-I Khufu-I changed the title infiniteQuery continues to refetch data even there are no more observers infiniteQuery continues to refetch data even if there are no more observers Dec 28, 2020
@FMCorz
Copy link

FMCorz commented Jan 6, 2021

Same issue.

@Khufu-I
Copy link
Author

Khufu-I commented Feb 8, 2021

@boschni Thank you for addressing this issue. I noticed that with the latest update the CodeSandbox sample shows an error after the infinite query is cancelled and the React component is rendered again.
Please let me know if I've to change my code to consume the new changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants