Skip to content

test(react-query): replace hardcoded query keys with 'queryKey()' utility#10420

Merged
sukvvon merged 2 commits intomainfrom
test/react-query-replace-hardcoded-keys-with-queryKey
Apr 7, 2026
Merged

test(react-query): replace hardcoded query keys with 'queryKey()' utility#10420
sukvvon merged 2 commits intomainfrom
test/react-query-replace-hardcoded-keys-with-queryKey

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented Apr 7, 2026

🎯 Changes

  • Replace hardcoded query/mutation keys with queryKey() utility from @tanstack/query-test-utils across react-query test files
  • Applied to runtime tests (.test.tsx) and type tests (.test-d.tsx)

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Tests
    • Standardized test infrastructure across test suites to use a utility function for generating query and mutation keys, replacing hardcoded key literals for improved consistency and maintainability.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7bbab499-bc37-47b7-a7c9-69b7b5b08dcb

📥 Commits

Reviewing files that changed from the base of the PR and between 389bbca and 8bc6571.

📒 Files selected for processing (18)
  • packages/react-query/src/__tests__/infiniteQueryOptions.test-d.tsx
  • packages/react-query/src/__tests__/infiniteQueryOptions.test.tsx
  • packages/react-query/src/__tests__/mutationOptions.test-d.tsx
  • packages/react-query/src/__tests__/mutationOptions.test.tsx
  • packages/react-query/src/__tests__/queryOptions.test-d.tsx
  • packages/react-query/src/__tests__/ssr-hydration.test.tsx
  • packages/react-query/src/__tests__/suspense.test.tsx
  • packages/react-query/src/__tests__/useInfiniteQuery.test-d.tsx
  • packages/react-query/src/__tests__/useMutationState.test.tsx
  • packages/react-query/src/__tests__/usePrefetchInfiniteQuery.test-d.tsx
  • packages/react-query/src/__tests__/usePrefetchQuery.test-d.tsx
  • packages/react-query/src/__tests__/useQueries.test-d.tsx
  • packages/react-query/src/__tests__/useQueries.test.tsx
  • packages/react-query/src/__tests__/useQuery.test-d.tsx
  • packages/react-query/src/__tests__/useQuery.test.tsx
  • packages/react-query/src/__tests__/useSuspenseInfiniteQuery.test-d.tsx
  • packages/react-query/src/__tests__/useSuspenseQueries.test-d.tsx
  • packages/react-query/src/__tests__/useSuspenseQuery.test-d.tsx

📝 Walkthrough

Walkthrough

This PR updates 18 test files across the react-query package to replace hardcoded query and mutation key array literals with dynamically generated keys using the queryKey() utility from @tanstack/query-test-utils.

Changes

Cohort / File(s) Summary
Infinite Query Tests
packages/react-query/src/__tests__/infiniteQueryOptions.test-d.tsx, infiniteQueryOptions.test.tsx, useInfiniteQuery.test-d.tsx, useSuspenseInfiniteQuery.test-d.tsx
Replaced hardcoded ['key'] tuples with queryKey() calls across all infinite query test cases and assertions.
Mutation Key Tests
packages/react-query/src/__tests__/mutationOptions.test-d.tsx, mutationOptions.test.tsx, useMutationState.test.tsx
Updated mutationKey values from hardcoded array literals (e.g., ['key'], ['with-vars']) to queryKey() generated values across all mutation test invocations and filtering logic.
Single Query Tests
packages/react-query/src/__tests__/queryOptions.test-d.tsx, useQuery.test-d.tsx, useQuery.test.tsx, useSuspenseQuery.test-d.tsx, usePrefetchQuery.test-d.tsx
Replaced static queryKey literals with queryKey() utility calls in type assertions and runtime tests for single-query hooks and options.
Multiple Queries Tests
packages/react-query/src/__tests__/useQueries.test-d.tsx, useQueries.test.tsx, useSuspenseQueries.test-d.tsx
Replaced hardcoded queryKey array literals (['key1'], ['key2'], ['todos-key'], etc.) with queryKey() generated values and stable key composition patterns.
Prefetch Infinite Query Tests
packages/react-query/src/__tests__/usePrefetchInfiniteQuery.test-d.tsx
Updated type-level usePrefetchInfiniteQuery test cases to use queryKey() instead of literal ['key'] tuple.
SSR and Suspense Tests
packages/react-query/src/__tests__/ssr-hydration.test.tsx, suspense.test.tsx
Changed hardcoded string-array query keys to dynamically generated keys via queryKey() to ensure consistent key identity across server and client prefetch/hydration scenarios and Suspense Timer tests.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • TanStack/query#10417: Applies the same test refactoring pattern in vue-query package test files, replacing hardcoded key literals with queryKey() utility.
  • TanStack/query#10419: Implements identical test-only changes in preact-query test suite, migrating hardcoded query/mutation keys to queryKey() generated values.
  • TanStack/query#10418: Performs the same code-level test refactoring in angular-query-experimental package tests, consistently replacing static key arrays with queryKey() calls.

Poem

🐰 Keys once carved in stone so cold,
Now dance freely, young and bold!
Utility-born, each test's delight,
Dynamic keys spark TypeScript light,
Our warren cheers—consistency's might! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 26.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: replacing hardcoded query keys with the queryKey() utility across react-query test files.
Description check ✅ Passed The description includes a clear summary of changes and follows the template with all key sections completed, including checklist items and release impact assessment.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/react-query-replace-hardcoded-keys-with-queryKey

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Apr 7, 2026

View your CI Pipeline Execution ↗ for commit 8bc6571

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 1m 46s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-07 07:03:35 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

🚀 Changeset Version Preview

No changeset entries found. Merging this PR will not cause a version bump for any packages.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 7, 2026

More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@10420

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@10420

@tanstack/preact-query

npm i https://pkg.pr.new/@tanstack/preact-query@10420

@tanstack/preact-query-devtools

npm i https://pkg.pr.new/@tanstack/preact-query-devtools@10420

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@10420

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@10420

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@10420

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@10420

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@10420

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@10420

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@10420

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@10420

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@10420

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@10420

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@10420

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@10420

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@10420

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@10420

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@10420

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@10420

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@10420

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@10420

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@10420

commit: 8bc6571

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

size-limit report 📦

Path Size
react full 11.98 KB (0%)
react minimal 9.01 KB (0%)

@sukvvon sukvvon self-assigned this Apr 7, 2026
@sukvvon sukvvon merged commit f699190 into main Apr 7, 2026
8 checks passed
@sukvvon sukvvon deleted the test/react-query-replace-hardcoded-keys-with-queryKey branch April 7, 2026 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant