Skip to content

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

Closed
@soorria

Description

@soorria

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions