TanStack / query

🤖 Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query.
https://tanstack.com/query
MIT License
40.1k stars 2.69k forks source link

In the underlying code, pages in the getNextPageParam method in infiniteQueryBehavior is undefined. #7364

Closed arianshirepublik closed 2 weeks ago

arianshirepublik commented 2 weeks ago

Describe the bug

We call the useInfiniteQuery function in @tanstack/react-query": "5.13.4":

const { refetch, data, isLoading, isFetching, isFetchingNextPage, fetchNextPage, hasNextPage, isSuccess, isFetched, error, isError, } = useInfiniteQuery({ queryKey: cacheKey, queryFn: async ({ pageParam }) => { const params = { [nextPageParam]: pageParam || nextPageDefault, limit: 50, reactions: isSubscription ? {} : { counts: true, own: true }, ...(ranking && { ranking }), }

  let result

  switch (feedGroup) {
    case 'timeline':
      result = await get({
        path: '',
        params,
      })
      break
    case 'trending':
      result = await get({
        path: '',
        params,
      })
      break
    case 'subscription':
      if (!userId) return
      result = await get({
        path: `/`,
        params,
      })
      break
    case 'exclusive':
      result = await get({
        path: '/',
        params,
      })
      break
    default:
      result = await doFeedRequest<IActivityItem>(
        client,
        feedGroup,
        feedId,
        params
      )
      break
  }
  let data = result?.results || []
  data = data.filter(
    (activity) => activity.object && typeof activity.object === 'object'
  )
  if (appConfig.disableRecommendations) {
    data = removeRecommendations(data)
  }
  cacheActivitiesReactions(data)
  return {
    data,
    next: result?.next ? parse(result?.next)?.[nextPageParam] : undefined,
  }
},
enabled: !isOnline || (!!client && enabled),
getNextPageParam: (lastPage) => lastPage?.next,
initialPageParam: '',

})

Will appear:

image

Your minimal, reproducible example

NO

Steps to reproduce

image

Expected behavior

no errors

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

Chrome Version 124.0.6367.62 (Official Build) (arm64)

Tanstack Query adapter

None

TanStack Query version

@tanstack/react-query": "5.13.4"

TypeScript version

"typescript": "5.2.2",

Additional context

No response

TkDodo commented 2 weeks ago

Thank you for filing this issue, but we need more information before looking into this.

Specifically, a minimal, standalone, runnable reproduction is needed - preferably with codesandbox or stackblitz. If your issue is TypeScript related, prefer a TypeScript playground.

We'll close this issue for now, but we'll certainly re-open it if there is a proper reproduction.