From 1c673151df3da1e03d027ce32a1d0871d1107491 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Mar 2026 09:41:45 +0000 Subject: [PATCH 1/4] Initial plan From 4c7e56600e2a5213ceead85e4a3937af472482ef Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Mar 2026 09:45:04 +0000 Subject: [PATCH 2/4] fix: add "infinite" suffix to useInfiniteQuery queryKey to prevent clash with useQuery Co-authored-by: longzheng <484912+longzheng@users.noreply.github.com> --- packages/openapi-react-query/src/index.ts | 3 +- .../openapi-react-query/test/index.test.tsx | 52 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/packages/openapi-react-query/src/index.ts b/packages/openapi-react-query/src/index.ts index fb9683164..689d458cd 100644 --- a/packages/openapi-react-query/src/index.ts +++ b/packages/openapi-react-query/src/index.ts @@ -229,9 +229,10 @@ export default function createClient { const { pageParamName = "cursor", ...restOptions } = options; const { queryKey } = queryOptions(method, path, init); + const infiniteQueryKey = [...queryKey, "infinite"] as const; return useInfiniteQuery( { - queryKey, + queryKey: infiniteQueryKey, queryFn: async ({ queryKey: [method, path, init], pageParam = 0, signal }) => { const mth = method.toUpperCase() as Uppercase; const fn = client[mth] as ClientMethod; diff --git a/packages/openapi-react-query/test/index.test.tsx b/packages/openapi-react-query/test/index.test.tsx index 78715e643..55f916016 100644 --- a/packages/openapi-react-query/test/index.test.tsx +++ b/packages/openapi-react-query/test/index.test.tsx @@ -1268,5 +1268,57 @@ describe("client", () => { expect(result.current.data).toEqual([1, 2, 3, 4, 5, 6]); }); + it("should not clash with useQuery when using the same method, path, and params", async () => { + const fetchClient = createFetchClient({ baseUrl }); + const client = createClient(fetchClient); + + useMockRequestHandler({ + baseUrl, + method: "get", + path: "/paginated-data", + status: 200, + body: { items: [1, 2, 3], nextPage: 1 }, + }); + + const { result } = renderHook( + () => ({ + query: client.useQuery("get", "/paginated-data", { + params: { + query: { + limit: 3, + }, + }, + }), + infiniteQuery: client.useInfiniteQuery( + "get", + "/paginated-data", + { + params: { + query: { + limit: 3, + }, + }, + }, + { + getNextPageParam: (lastPage) => lastPage.nextPage, + initialPageParam: 0, + }, + ), + }), + { wrapper }, + ); + + await waitFor(() => { + expect(result.current.query.isSuccess).toBe(true); + expect(result.current.infiniteQuery.isSuccess).toBe(true); + }); + + // useQuery should return flat data + expect(result.current.query.data).toEqual({ items: [1, 2, 3], nextPage: 1 }); + + // useInfiniteQuery should return paginated data with pages array + expect(result.current.infiniteQuery.data?.pages).toHaveLength(1); + expect(result.current.infiniteQuery.data?.pages[0]).toEqual({ items: [1, 2, 3], nextPage: 1 }); + }); }); }); From c77ec832e33c91a5e3c9cc344f2a7ebf2961f26f Mon Sep 17 00:00:00 2001 From: Long Zheng Date: Thu, 12 Mar 2026 10:19:25 +1100 Subject: [PATCH 3/4] Fix type --- packages/openapi-react-query/src/index.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/openapi-react-query/src/index.ts b/packages/openapi-react-query/src/index.ts index 689d458cd..e85952c73 100644 --- a/packages/openapi-react-query/src/index.ts +++ b/packages/openapi-react-query/src/index.ts @@ -113,7 +113,7 @@ export type UseInfiniteQueryMethod, Options["select"]>, - QueryKey, + readonly [...QueryKey, "infinite"], unknown >, "queryKey" | "queryFn" @@ -229,11 +229,10 @@ export default function createClient { const { pageParamName = "cursor", ...restOptions } = options; const { queryKey } = queryOptions(method, path, init); - const infiniteQueryKey = [...queryKey, "infinite"] as const; return useInfiniteQuery( { - queryKey: infiniteQueryKey, - queryFn: async ({ queryKey: [method, path, init], pageParam = 0, signal }) => { + queryKey: [...queryKey, "infinite"], + queryFn: async ({ pageParam = 0, signal }) => { const mth = method.toUpperCase() as Uppercase; const fn = client[mth] as ClientMethod; const mergedInit = { From b05bbb934677629869daae643b1237ce3704ddf0 Mon Sep 17 00:00:00 2001 From: Long Zheng Date: Thu, 12 Mar 2026 10:27:43 +1100 Subject: [PATCH 4/4] Add changeset --- .changeset/crisp-baths-jam.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/crisp-baths-jam.md diff --git a/.changeset/crisp-baths-jam.md b/.changeset/crisp-baths-jam.md new file mode 100644 index 000000000..d9d9d4e42 --- /dev/null +++ b/.changeset/crisp-baths-jam.md @@ -0,0 +1,5 @@ +--- +"openapi-react-query": minor +--- + +Fix useInfiniteQuery query key collision with useQuery