Skip to content

Conversation

@AlexanderKaran
Copy link
Contributor

@AlexanderKaran AlexanderKaran commented Nov 11, 2025

🎯 Changes

Upgrade TanStack Query to use Vitest 4. Most changes were around mocks, testing functions being used and some config tweaks.

A few gotchas I am unsure about:

  • Had to pin Vite version in overrides
  • Vitest 4 has some changes under the hood that causes a few tests to fail in react-query not 100% sure about the solution

Please let me know if I have messed with things that should not be touched.

✅ 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

Release Notes

  • Chores

    • Updated development dependencies including Vite, Vitest, and TypeScript support tools across all packages and examples.
    • Updated JSX compiler option from "preserve" to "react-jsx" in TypeScript configurations.
    • Enhanced ESLint configuration with additional testing rules.
  • Tests

    • Improved test infrastructure with better mock lifecycle management and async handling.
    • Refined test assertions and mock implementations for more precise verification.
    • Updated Vitest coverage patterns and configuration.

✏️ Tip: You can customize this high-level summary in your review settings.

@changeset-bot
Copy link

changeset-bot bot commented Nov 11, 2025

⚠️ No Changeset found

Latest commit: d97edbc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 11, 2025

📝 Walkthrough

Walkthrough

Updates Vite and Vitest dependencies across examples and packages, adds Next.js route type imports, converts React examples to use react-jsx, refines test mock utilities and assertions, and modernizes ESLint configuration.

Changes

Cohort / File(s) Summary
Vite Dependency Bumps (6.4.1)
examples/react/*/package.json, examples/solid/*/package.json, examples/svelte/*/package.json, examples/vue/*/package.json, integrations/*/package.json, packages/vue-query-devtools/package.json
Uniform bump of vite devDependency from ^6.3.6 to ^6.4.1 across ~35 example and integration package files
Root Package Configuration
package.json
Multiple updates: Vitest 3.2.4→4.0.17, @vitest/coverage-istanbul 3.2.4→4.0.6, @vitest/eslint-plugin ^1.1.36→^1.4.0, added pnpm overrides for @types/node, vite, esbuild; updated @types/react and @types/react-dom to ^19.2.x; added TypeScript 5.1–5.7 version aliases
Next.js Type Imports
examples/react/auto-refetching/next-env.d.ts, examples/react/infinite-query-with-max-pages/next-env.d.ts, examples/react/load-more-infinite-scroll/next-env.d.ts, examples/react/nextjs/next-env.d.ts, examples/react/optimistic-updates-cache/next-env.d.ts, examples/react/optimistic-updates-ui/next-env.d.ts, examples/react/pagination/next-env.d.ts, examples/react/prefetching/next-env.d.ts
Added import of ./.next/types/routes.d.ts to augment type declarations
React JSX Configuration Updates
examples/react/auto-refetching/tsconfig.json, examples/react/infinite-query-with-max-pages/tsconfig.json, examples/react/load-more-infinite-scroll/tsconfig.json, examples/react/nextjs-app-prefetching/tsconfig.json, examples/react/nextjs-suspense-streaming/tsconfig.json, examples/react/nextjs/tsconfig.json, examples/react/optimistic-updates-cache/tsconfig.json, examples/react/optimistic-updates-ui/tsconfig.json, examples/react/pagination/tsconfig.json, examples/react/prefetching/tsconfig.json
Changed compilerOptions.jsx from "preserve" to "react-jsx"; nextjs-app-prefetching also adds .next/dev/types to include paths
Angular Query Devtools Test Mocks
packages/angular-query-experimental/src/__tests__/inject-devtools-panel.test.ts, packages/angular-query-experimental/src/__tests__/with-devtools.test.ts
Extracted mock factory functions (MockTanstackQueryDevtoolsPanel, MockTanstackQueryDevtools); added vi.clearAllMocks() in beforeEach; added awaits for vi.dynamicImportSettled() in async test flows
Vue Query Mock Refactoring
packages/vue-query/src/__mocks__/useBaseQuery.ts, packages/vue-query/src/__mocks__/useQueryClient.ts
Replaced explicit Mock<...> type annotations with inferred types; changed useBaseQuery import approach to use typed module alias; removed unrefQueryArgs export from useBaseQuery mock
Vue Query Test Updates
packages/vue-query/src/__tests__/queryClient.test.ts, packages/vue-query/src/__tests__/useQueries.test.ts, packages/vue-query/src/__tests__/useQueryClient.test.ts
Replaced restoreAllMocks() with clearAllMocks() in beforeEach; dynamically mocked QueryClient prototype methods; changed expectations to use expect.objectContaining for flexible assertions; switched from direct imports to vi.mocked namespace wrappers for vue-demi functions
Build Configuration Updates
packages/solid-query-devtools/vite.config.ts, packages/query-codemods/vite.config.ts
Changed defineConfig import source from 'vite' to 'vitest/config'; refined vitest coverage include pattern from src/**/* to explicit file extensions
ESLint Configuration
eslint.config.js
Added vitest/no-standalone-expect rule with additionalTestBlockFunctions option to test file rules; spreads recommended rules explicitly
Query Core Test Utilities
packages/query-core/src/__tests__/timeoutManager.test.tsx, packages/query-core/src/__tests__/query.test.tsx
Updated consoleErrorSpy type from ReturnType to MockInstance; replaced try/catch error handling with expect(...).rejects.toBeInstanceOf assertions
React Query Test Assertions
packages/react-query/src/__tests__/useQuery.promise.test.tsx, packages/react-query/src/__tests__/usePrefetchInfiniteQuery.test.tsx
Added test timeout (10,000 ms); extended useFakeTimers with timer functions; introduced vi.waitFor blocks for state synchronization; added createFallback() helper factory; replaced inline catch blocks with rejects assertions
Solid Query Mock Updates
packages/solid-query/src/__tests__/useQueries.test.tsx
Changed QueriesObserver spy mockImplementation to accept (client, queries) arguments instead of single fn parameter
Persist Client Test Assertions
packages/query-persist-client-core/src/__tests__/createPersister.test.ts
Replaced toHaveBeenCalledOnce() + toHaveBeenCalledWith() with toHaveBeenCalledExactlyOnceWith() for stricter call count verification
Vue Query Devtools
packages/vue-query-devtools/src/devtoolsPanel.vue
Relaxed style computed property type annotation from StyleValue to any
Package Dependency Updates
packages/react-query/package.json
Updated @testing-library/react-render-stream from ^2.0.0 to ^2.0.2
ESLint Plugin Test Structure
packages/eslint-plugin-query/src/__tests__/no-void-query-fn.test.ts
Removed outer test() wrapper and vitest import; moved ruleTester.run() to primary test body; simplified test structure while preserving validation content

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

dependencies, devtools, testing, configuration

Suggested reviewers

  • manudeli

Poem

🐰 With Vite now swifter and vitest more keen,
React's jsx shines in a modern green,
Mocks refactored, assertions precise,
Next.js routes imported—configuration so nice!
Build tools evolve, tests run pristine, ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 clearly and specifically identifies the main change: upgrading to Vitest v4, which is the primary objective of this PR.
Description check ✅ Passed The PR description covers the main changes (Vitest 4 upgrade, mock/config adjustments), includes acknowledgment of uncertainties, marks the checklist items, and specifies this is dev-only with no release impact.

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


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Collaborator

@TkDodo TkDodo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome. can you please fix the conflicts and I’ll try to ship it


expect(queryFn).toHaveBeenCalledOnce()
expect(queryFn).toHaveBeenCalledWith(context)
expect(queryFn).toHaveBeenCalledExactlyOnceWith(context)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh this is a nice new matcher 👍


afterEach(() => {
vi.useRealTimers()
Fallback.mockClear()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what’s that doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left over from debugging why the test broke on the upgrade. Forgot to remove sorry

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

@AlexanderKaran
Copy link
Contributor Author

@TkDodo sorry missed these comments will get this fixed tomorrow/day after

@AlexanderKaran
Copy link
Contributor Author

@TkDodo Fixed merge conflicts but now one test is failing, need to double check why

@TkDodo
Copy link
Collaborator

TkDodo commented Jan 16, 2026

@AlexanderKaran trying to fix the pipeline ...

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@package.json`:
- Around line 89-93: The pnpm override forcing vite ^6.4.1 conflicts with the
Vue 2 example packages (examples/vue/2.7-basic and examples/vue/2.6-basic) which
require vite ^4.5.14 for [email protected]; fix by updating package.json
pnpm.overrides to either (a) add package-specific overrides that pin vite to
^4.5.14 for those two example packages, or (b) exclude those example packages
from the global vite override, or (c) update the example projects to be
compatible with vite ^6.x and replace vite-plugin-vue2 with a compatible plugin;
locate and change the pnpm.overrides entry in package.json and the vite entries
in examples/vue/2.7-basic and examples/vue/2.6-basic to implement one of these
fixes.
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 71dfd88 and f013619.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • package.json
🔇 Additional comments (1)
package.json (1)

56-57: All Vitest v4/Vite v6 versions are compatible and properly aligned.

vitest 4.0.17 supports Vite 5 and 6 (range: ^5.0.0 || ^6.0.0), and the included plugins (@vitest/coverage-istanbul 4.0.6, @vitest/eslint-plugin 1.4.0) are part of the Vitest 4.x ecosystem. The pnpm overrides for vite, esbuild, and @types packages are standard workspace management without conflicts.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@TkDodo
Copy link
Collaborator

TkDodo commented Jan 16, 2026

the remaining errors are legit I think, can you take another look please?

@AlexanderKaran
Copy link
Contributor Author

@TkDodo Digging into it now

- Fallback UI is not reset between tests -> moved to create a function for each
- ruleTests needs to be top level
@AlexanderKaran
Copy link
Contributor Author

@TkDodo Did some tweaks and running test locally is now passing

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@examples/react/simple/package.json`:
- Around line 17-19: Update the `@vitejs/plugin-react` dependency in package.json
from "@vitejs/plugin-react": "^4.3.4" to a v5+ range (for example "^5.0.0" or
"^5.x") so it is compatible with Vite 6.4.1; locate the dependency entry for
"@vitejs/plugin-react" and bump the version string, then run install and verify
the dev server/tests (Vite and Vitest) start correctly.

In `@examples/svelte/ssr/package.json`:
- Line 21: Update the vite dependency in package.json to pin it to Vite 5 for
SvelteKit 2.42 compatibility: replace the current "vite": "^6.4.1" entry with a
Vite 5.x range (e.g. "vite": "^5.x") so the project uses a supported peer
version; ensure package.json's "vite" key is updated and run an install to lock
the new version.

@sentry
Copy link

sentry bot commented Jan 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 36.86%. Comparing base (0525ad1) to head (d97edbc).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #9862      +/-   ##
==========================================
- Coverage   46.05%   36.86%   -9.19%     
==========================================
  Files         200      245      +45     
  Lines        8542    11102    +2560     
  Branches     1976     2079     +103     
==========================================
+ Hits         3934     4093     +159     
- Misses       4150     6484    +2334     
- Partials      458      525      +67     
Components Coverage Δ
@tanstack/angular-query-experimental 46.35% <ø> (-47.51%) ⬇️
@tanstack/eslint-plugin-query 88.92% <ø> (+5.10%) ⬆️
@tanstack/query-async-storage-persister 43.85% <ø> (ø)
@tanstack/query-broadcast-client-experimental 24.39% <ø> (ø)
@tanstack/query-codemods 0.00% <ø> (ø)
@tanstack/query-core 75.54% <ø> (-22.34%) ⬇️
@tanstack/query-devtools 3.38% <ø> (ø)
@tanstack/query-persist-client-core 80.12% <ø> (+0.12%) ⬆️
@tanstack/query-sync-storage-persister 84.61% <ø> (ø)
@tanstack/query-test-utils 77.77% <ø> (ø)
@tanstack/react-query 29.00% <ø> (-67.74%) ⬇️
@tanstack/react-query-devtools 9.25% <ø> (ø)
@tanstack/react-query-next-experimental ∅ <ø> (∅)
@tanstack/react-query-persist-client 100.00% <ø> (ø)
@tanstack/solid-query 53.52% <ø> (-24.29%) ⬇️
@tanstack/solid-query-devtools 64.17% <ø> (ø)
@tanstack/solid-query-persist-client 100.00% <ø> (ø)
@tanstack/svelte-query ∅ <ø> (∅)
@tanstack/svelte-query-devtools ∅ <ø> (∅)
@tanstack/svelte-query-persist-client ∅ <ø> (∅)
@tanstack/vue-query 35.67% <100.00%> (-36.25%) ⬇️
@tanstack/vue-query-devtools ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@integrations/react-vite/package.json`:
- Around line 11-14: Update package.json to move the build tooling packages from
dependencies to devDependencies: remove "@vitejs/plugin-react" and "vite" from
the "dependencies" section and add them under "devDependencies" (keeping their
existing versions), leaving runtime packages like "react" and "react-dom" in
dependencies; ensure package.json remains valid JSON and run an install to
update lockfile if present.

@TkDodo TkDodo merged commit 9ff3de7 into TanStack:main Jan 18, 2026
8 of 9 checks passed
@TkDodo
Copy link
Collaborator

TkDodo commented Jan 18, 2026

Thank you, great work 🎉

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