Skip to content

Buggy interaction between returning filtered data in the combine property for useQueries function #7000

@skalidindi

Description

@skalidindi

Describe the bug

I am trying to use the useQueries function to call a bunch of APIs in different regions. I expect some of them to give back 404 errors and thus I want to use the combine method to filter out only the successful methods.

However, I noticed that doing something like the following

useQueries({
    queries,
    combine: (results) => {
      // const data = results.filter((result) => result.isSuccess).map((result) => result.data);
      // console.log(results);
      return {
        isLoading: results.some((result) => result.isLoading),
        data: results.filter((result) => result.isSuccess).map((result) => result.data)
      };
    },
  });

where data is filtering out only the successful results causes isLoading to never settle on false and thus component stays stuck in the loading state forever.
However, if I remove the filter block, then it settles to false just fine.

Your minimal, reproducible example

https://codesandbox.io/p/devbox/old-monad-pyr3qf

Steps to reproduce

View at the code sandbox link.
Notice how loading stays stuck on loading state.
If you remove the filter then it works fine.
Also note that you need to have atleast one API be in an error state for this bug to show up.

Expected behavior

I expect the useQueries function to settle on isLoading after all calls have finished and thus all queries in the array should be isLoading false.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: MacOS
  • Browser: Arc
  • Version: 5.18.1

Tanstack Query adapter

None

TanStack Query version

5.18.1

TypeScript version

4.4.4

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions