-
-
Notifications
You must be signed in to change notification settings - Fork 633
Description
openapi-react-query version
0.5.4
Description
Bug
When calling useInfiniteQuery with initialPageParam: undefined, the first page request still includes the page parameter in the query string with value 0.
Root cause
In the queryFn implementation, pageParam defaults to 0:
queryFn: async ({ pageParam = 0, signal }) => {
query: {
[pageParamName]: pageParam, // sends e.g. after=0 on first page
}
}When initialPageParam is undefined, pageParam is undefined, which the destructuring default then replaces with 0. The page param is then always included in the query — even for the first page.
Expected behavior
When pageParam is undefined (i.e. the initial page), the page param should be omitted from the query entirely.
Suggested fix
queryFn: async ({ pageParam, signal }) => {
query: {
...(pageParam !== undefined ? { [pageParamName]: pageParam } : {}),
}
}Impact
APIs that use cursor-based pagination receive an unexpected cursor=0 (or equivalent) on the first request, which they may not handle gracefully — since 0 is not a valid cursor value.
Reproduction
Craft an infinite query and set the initialPageParam as undefined. See that the request includes the page param as 0
Expected result
When pageParam is undefined (i.e. the initial page), the page param should be omitted from the query entirely.
Extra
- I’m willing to open a PR (see CONTRIBUTING.md)