Skip to content

Fix useInfiniteQuery query key collision with useQuery#2671

Open
longzheng wants to merge 4 commits intoopenapi-ts:mainfrom
longzheng:copilot/fix-useinfinitequery-clash
Open

Fix useInfiniteQuery query key collision with useQuery#2671
longzheng wants to merge 4 commits intoopenapi-ts:mainfrom
longzheng:copilot/fix-useinfinitequery-clash

Conversation

@longzheng
Copy link

Changes

useInfiniteQuery and useQuery generate identical query keys for the same method/path/params, causing React Query cache collisions. Since useInfiniteQuery wraps data in InfiniteData<TData> while useQuery returns plain TData, the shared cache entry causes TypeError: Cannot read properties of undefined (reading 'length') when getNextPageParam tries to access data.pages.

Appends "infinite" to the query key tuple for useInfiniteQuery, e.g. ["get", "/api/test", init, "infinite"], so the two hooks maintain separate cache entries.

// before
const {} = $api.useQuery("get", "/api/test", {}, {}); // queryKey ["get", "/api/test", init]
const {} = $api.useInfiniteQuery("get", "/api/test", {}, {}); // queryKey ["get", "/api/test", init]

// after
const {} = $api.useInfiniteQuery("get", "/api/test", {}, {}); // queryKey ["get", "/api/test", init, 'infinite']

Fixes #2184

How to Review

Added a test to reproduce query key collision and resulting error when loading data. Revert change to see test fail

      return useInfiniteQuery(
        {
-          queryKey: [...queryKey, "infinite"],
+          queryKey,

Checklist

  • Unit tests updated
  • docs/ updated (if necessary)
  • pnpm run update:examples run (only applicable for openapi-typescript)

Copilot AI and others added 3 commits March 11, 2026 09:41
…ash with useQuery

Co-authored-by: longzheng <484912+longzheng@users.noreply.github.com>
@longzheng longzheng requested a review from a team as a code owner March 11, 2026 23:25
@longzheng longzheng requested a review from drwpow March 11, 2026 23:25
@netlify
Copy link

netlify bot commented Mar 11, 2026

👷 Deploy request for openapi-ts pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit b05bbb9

@changeset-bot
Copy link

changeset-bot bot commented Mar 11, 2026

🦋 Changeset detected

Latest commit: b05bbb9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
openapi-react-query Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useInfiniteQuery clashes with useQuery query key for the same method & path & params

2 participants