query icon indicating copy to clipboard operation
query copied to clipboard

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

Open BierDav opened this issue 1 year ago • 9 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

BierDav avatar Jun 06 '24 06:06 BierDav

can you please show a typescript playground? thanks

TkDodo avatar Jun 07 '24 20:06 TkDodo

closing until we get a typescript playground reproduction

TkDodo avatar Jul 17 '24 13:07 TkDodo

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

BierDav avatar Jul 17 '24 15:07 BierDav

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

BierDav avatar Jul 17 '24 16:07 BierDav

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 ..." ?

TkDodo avatar Jul 26 '24 10:07 TkDodo

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

BierDav avatar Jul 26 '24 11:07 BierDav

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

TkDodo avatar Jul 26 '24 13:07 TkDodo

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 ?

lachlancollins avatar Jul 26 '24 14:07 lachlancollins

yes, sorry 🙈

TkDodo avatar Jul 26 '24 14:07 TkDodo

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

samuelchau avatar Dec 17 '24 19:12 samuelchau