query
query copied to clipboard
getNextPageParam throws an error when setting the data for an infinite query to empty lists for pages & pageParams
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
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
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