Unintentionally changing queryKey on each page of infinite queries in the @tanstack/react-query plugin #2050
Labels
bug 🔥
Something isn't working
prioritized 🚚
This issue has been prioritized and will be worked on soon
Description
Bug:
When using infinite queries in the @tanstack/react-query plugin, each page request uses the base parameters from the
queryKey
, plus any pagination parameters that are added for that page. However, thequeryKey
is accidentally altered each time this happens, with the pagination parameters unwittingly included.The generated code does not copy the
queryKey
, just references it, when creating theparams
for a specific page. The body, headers, path and query are replaced onqueryKey
each timecreateInfiniteParams
is called with different pagination parameters.Screenshot:
Potential fix:
The generated line in
createInfiniteParams
:const params = queryKey[0]
should be replaced with a copy of
queryKey
instead, e.g.:const params = { ...queryKey[0] }
to prevent unintentional changes to the
queryKey
for the same query.Source code reference:
openapi-ts/packages/openapi-ts/src/plugins/@tanstack/query-core/infiniteQueryOptions.ts
Lines 51 to 56 in cb651c0
Reproducible example or configuration
No response
OpenAPI specification (optional)
No response
System information (optional)
No response
The text was updated successfully, but these errors were encountered: