Skip to content

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

Closed

Description

@Khufu-I

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

Activity

  1. jayakusumah commented on Dec 27, 2020

    @jayakusumah

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

  2. GermaVinsmoke commented on Dec 28, 2020

    @GermaVinsmoke

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

  3. 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[/+] on Dec 28, 2020
  4. FMCorz commented on Jan 6, 2021

    @FMCorz

    Same issue.

  5. Khufu-I commented on Feb 8, 2021

    @Khufu-I
    Author

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions