Skip to content
Source
Sign inSign up
TanStack/db

useLiveInfiniteQuery doesn't fetch more data when collection has no more items #968

Send to my agent
Openbeliever(GitHub profile, opens in a new tab) opened this issue 2 comments
  • I've validated the bug against the latest version of DB packages

Describe the bug

I've converted a useInfiniteQuery from TanStack Query to useLiveInfiniteQuery. Initially it loads data and also loads more data as long as there is more data in the collection.

I expected that the queryFn would re-trigger when the collection had no more data to fetch more from the source, but once it displays all the items in the collection it does nothing.

I noticed that queryFn has a pageParam, but it's always undefined and is only logged on initial load. I might be misunderstanding how it should work?

Might be related to #872

(Note: I know that my queryFn would overwrite existing items, but that's the next thing to fix 😄)

export const moviesCollection = createCollection(
  queryCollectionOptions({
    getKey: (item) => item.id,
    queryClient,
    queryFn: async ({ pageParam }) => {
      console.log('MOVIES', { pageParam })
      const url = new URL('https://movies.willcodefor.beer') // Returns 20 items

      url.searchParams.set('page', '1')

      const response = await fetch(url.toString(), {
        headers: { Accept: 'application/json' },
      })
      return response.json()
    },
    queryKey: ['movies'],
    schema,
  })
)

export function Movies() {
  const {
    data: movies,
    fetchNextPage,
    isFetchingNextPage,
  } = useLiveInfiniteQuery(
    (q) =>
      q.from({ alerts: moviesCollection }).orderBy(({ alerts }) => alerts.watchedAt.Time, 'desc'),
    {
      getNextPageParam: (_lastPage, _allPages, lastPageParam) => lastPageParam + 1,
      initialPageParam: 0,
    }
  )

  return (
    <List.Infinite
      data={movies}
	  // This is called when the list reaches a threshold
      fetchNextPage={fetchNextPage}
      id="id"
      isFetchingNextPage={isFetchingNextPage}
      refetch={moviesCollection.utils.refetch}
      renderItem={({ item }) => (
        <View style={{ padding: 16, rowGap: 8 }}>
          <Text>{item.title}</Text>
          <Text numberOfLines={3}>{item.overview}</Text>
        </View>
      )}
    />
  )
}

To Reproduce Steps to reproduce the behavior:

  1. All items in collection are loaded in list
  2. Keep scrolling down
  3. List never updates

Smartphone:

  • Device: iPhone 17 Pro
  • OS: iOS 26
  • React Native 0.82.1
  1. The migration for this report landed in #1806 as part of #1657. Query Collections use QueryObserver, not InfiniteQueryObserver: their queryFn receives meta.loadSubsetOptions, not a server pageParam. The previously ignored getNextPageParam option now produces a clear error rather than silently doing nothing.

    For this endpoint, use syncMode: 'on-demand' and translate the requested filter/order/offset/limit into server requests. A fixed-page endpoint may need several backend pages to fulfill one live-query request (including its extra-row lookahead). The server-pagination guide includes that adapter pattern and distinguishes offset handling from separate cursor hints.

    Rechecked the three React infinite-query/server-pagination suites on current main plus the #1822 follow-up: 145 tests pass, including provider/UI page-size mismatches and tie-group cases. This is local React test evidence, not an iPhone/React Native run.

    This fixes the ignored-option/API guidance problem; it does not make the original eager pageParam example fetch remotely or add a general server-page bridge. Keeping this issue open for confirmation that the documented on-demand replacement addresses the reported use case. The RFC remains open for final verification.

  2. The migration for this report landed in #1806 (see the maintainer reply above): Query Collections now reject getNextPageParam with a clear error, and the server-pagination guide covers the syncMode: 'on-demand' route. I think this can be closed.

Sign in to join this conversation.