Skip to content
Source
Sign inSign up
TanStack/query

`useSuspenseInfiniteQuery` does not create correct data #7693

Send to my agent
ClosedVenefilyn(GitHub profile, opens in a new tab) opened this issue 1 comment

Describe the bug

When going to a page that has useSuspenseInfiniteQuery it does not show the data as it should. Instead it feels like TanStack takes a normal query and hands it off as-is to the SuspenseInfiniteQuery part which errors out as it didn't expect the data to not have pages attribute

I had this issue popup on my own refactor over at https://github.com/packit/dashboard/pull/435

Uncaught TypeError: pages is undefined
    getNextPageParam infiniteQueryBehavior.ts:135
    hasNextPage infiniteQueryBehavior.ts:164
    createResult infiniteQueryObserver.ts:164
    updateResult queryObserver.ts:595
    setOptions queryObserver.ts:193
    setOptions infiniteQueryObserver.ts:84
    _a9 queryObserver.ts:86
    InfiniteQueryObserver infiniteQueryObserver.ts:64
    <anonymous> useBaseQuery.ts:68
    React 3
    useBaseQuery useBaseQuery.ts:66
    useSuspenseInfiniteQuery useSuspenseInfiniteQuery.ts:35
    ProjectsList ProjectsList.tsx:54 <-- my component

Your minimal, reproducible example

https://codesandbox.io/p/sandbox/dank-dew-5g5w8r

Steps to reproduce

  1. Open sandbox
  2. Click "Show Projects"

Expected behavior

Should load as normal and give us the format that

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • Firefox and Chrome has the same error (but different wording)

Tanstack Query adapter

react-query

TanStack Query version

v5.50.1

TypeScript version

No response

Additional context

No response

  1. ["projects"] is an infinite query, but you prefetch it with prefetchQuery. That puts the wrong structure in the cache. You need to prefetch it with prefetchInfiniteQuery

  2. TkDodo closed this

  3. TkDodo added labelsinvalid

Sign in to join this conversation.