Skip to content
Source
Sign inSign up
TanStack/query

[Bug?]: Result type of combine works not as expected #7522

Send to my agent
OpenBierDav(GitHub profile, opens in a new tab) opened this issue 12 comments

Describe the bug

I have already posted a question to the discord: https://discord.com/channels/719702312431386674/1003327027849474198/1247640278987309058

Unfortunately no one answered in the thread and in the meanwhile I'm pretty sure that this is an incorrect result type.

Steps to reproduce

    return createQueries(() => {
      const list = ["test1", "test2"];
      return ({
        queries: list .map((key) => ({
          queryKey: ["key", key],
          queryFn: () => true,
        })),
        combine: (results) => ({
          data: results.every(result => result.data)
        })
      });
    });

Expected behavior

As already said in the discord thread. I expect to just return a combined data and all other fields like isPending, isError and so on should be automatically handled by tanstack query. And if this is not possible, because I think in react it doesn't do that, it should be possible to freely define this result, because when we look at the react documentation (https://tanstack.com/query/latest/docs/framework/react/reference/useQueries#combine) clearly only uses data and pending

How often does this bug happen?

Every time

Screenshots or Videos

image

Platform

OS: Windows Browser: Chrome Node: v21.7.3

Tanstack Query adapter

solid-query

TanStack Query version

5.40.0

TypeScript version

No response

Additional context

No response

  1. can you please show a typescript playground? thanks

  2. TkDodo added labelstypes

  3. TkDodo added labelsneeds-info

  4. TkDodo added labelspackage: solid-query

  5. closing until we get a typescript playground reproduction

  6. TkDodo closed this

  7. Sorry I must have overseen the comment. If you really need a playground I can provide one.

  8. Your wish shall be granted: https://codesandbox.io/p/github/BierDav/temp-tanstack-query-ssr-bug/combine-not-working image What I want to add additionally is that there is also a bug in executing this code too as you can see on the right hand side of my screenshot: ➜ Network: use --host to expose

    TypeError: state.map is not a function
        at file:///project/workspace/node_modules/@tanstack/solid-query/build/dev.js:450:19
        at file:///project/workspace/node_modules/solid-js/dist/server.js:123:12
        at createMemo (file:///project/workspace/node_modules/solid-js/dist/server.js:95:9)
        at Module.createQueries (file:///project/workspace/node_modules/@tanstack/solid-query/build/dev.js:447:25)
        at __vite_ssr_exports__.default (/project/workspace/src/routes/index.tsx?pick=default&pick=$css:15:41)
        at Module.createComponent (file:///project/workspace/node_modules/solid-js/dist/server.js:353:15)
        at Promise.Comp [as resolved] (/project/workspace/node_modules/@solidjs/start/dist/router/lazyRoute.js:35:107)
        at wrap (file:///project/workspace/node_modules/solid-js/dist/server.js:591:30)
        at Module.createComponent (file:///project/workspace/node_modules/solid-js/dist/server.js:353:15)
        at Object.outlet (/project/workspace/node_modules/@solidjs/router/dist/routing.js:450:53)
        at get children [as children] (/project/workspace/node_modules/@solidjs/router/dist/routers/components.jsx:138:23)
        at file:///project/workspace/node_modules/solid-js/dist/server.js:216:35
        at file:///project/workspace/node_modules/solid-js/dist/server.js:179:49
        at createMemo (file:///project/workspace/node_modules/solid-js/dist/server.js:95:9)
        at children (file:///project/workspace/node_modules/solid-js/dist/server.js:179:16)
        at file:///project/workspace/node_modules/solid-js/dist/server.js:216:14
        at createMemo (file:///project/workspace/node_modules/solid-js/dist/server.js:95:9)
        at provider (file:///project/workspace/node_modules/solid-js/dist/server.js:211:12)
        at Module.createComponent (file:///project/workspace/node_modules/solid-js/dist/server.js:353:15)
        at children (/project/workspace/node_modules/@solidjs/router/dist/routers/components.jsx:135:49)
        at Show (file:///project/workspace/node_modules/solid-js/dist/server.js:421:9)
        at Module.createComponent (file:///project/workspace/node_modules/solid-js/dist/server.js:353:15)

    Please reopen this issue, if this would work it would really be an outstanding feature

  9. sorry, is this now a runtime issue (state.map is not a function) or a type level issue as you initially claimed with the screenshot showing "argument of type ... is not assignable to parameter of type ..." ?

  10. It is both, but i recommend to resolve the type issue first, maybe this resolves the other one too

  11. here is a typescript playground with the error.

    @lachlancollins can you take a look please? The same code works fine when using useQueries from @tanstack/react-query

  12. TkDodo reopened this

  13. TkDodo removed labelsneeds-info

  14. here is a typescript playground with the error.

    @lachlancollins can you take a look please? The same code works fine when using useQueries from @tanstack/react-query

    Did you mean to ping @ardeora ?

  15. yes, sorry 🙈

  16. Just wondering if this issue with createQueries for SolidJS has been fixed yet?

  17. Seems like this is still an issue. Trying to use with solid, but the combine method is typed incorrectly, it always expects the same results structure to be returned.

  18. So I think the issue is simply this type constraint:

    https://github.com/TanStack/query/blob/1fba7fc38b91be92d8c20e52935e89acd2921415/packages/solid-query/src/useQueries.ts#L189

    it doesn’t exist in the react adapter:

    https://github.com/TanStack/query/blob/07cbfe1b364fea5833feb01273a5f661fe2d8ff6/packages/react-query/src/useQueries.ts#L210

    I tried to remove it but hit some more type issues that seem to be solid specific, because we call createStore on that type, which has a constraint of T extends object. There are also some more, follow-up type errors on createMemo.

    Would love it if someone with more solid-js knowledge could take a look here 🙏

  19. TkDodo unassignedardeora

Sign in to join this conversation.