query icon indicating copy to clipboard operation
query copied to clipboard

getNextPageParam throws an error when setting the data for an infinite query to empty lists for pages & pageParams

Open soorria opened this issue 8 months ago • 0 comments

Describe the bug

[!note] not sure if this is a bug, or me doing something i shouldn't be

When I setQueryData for an infinite query to

{
	params: [],
	pageParams: []
}

getNextPageParams throws a TypeError because the lastPage argument is undefined

image

Your minimal, reproducible example

https://codesandbox.io/p/sandbox/tanstack-query-infinitequery-error-5zxhqx?file=%2Fsrc%2FApp.js%3A22%2C73

Steps to reproduce

Set query data for an infinite query w/ empty pages & page params

queryClient.setQueryData(queryKey, { pages: [], pageParams: [] })

(click the setQueryData button in the repro)

Expected behavior

I'd expect either getNextPageParam to not be called if pages is empty

How often does this bug happen?

Every time

Screenshots or Videos

image

Platform

  • OS: MacOS
  • Browser: Arc
  • Version: 126.0.6478.127 (Official Build) (arm64)

Tanstack Query adapter

react-query

TanStack Query version

v5.48.0

TypeScript version

No response

Additional context

No response

soorria avatar Jun 30 '24 00:06 soorria