Skip to content

Conversation

@sukvvon
Copy link
Contributor

@sukvvon sukvvon commented Dec 28, 2025

🎯 Changes

Add useMutation and useMutationState tests for SSR in ssr.test.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

  • New Features

    • Added public exports for mutation hooks (useMutation and useMutationState) to the package API.
  • Tests

    • Added server-side rendering tests for mutation hooks, validating initial idle/pending indicators and that mutation state is empty in server-rendered output.

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

@changeset-bot
Copy link

changeset-bot bot commented Dec 28, 2025

⚠️ No Changeset found

Latest commit: e72096f

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 Dec 28, 2025

📝 Walkthrough

Walkthrough

Adds SSR tests for mutation hooks and exposes useMutation and useMutationState on the package's public exports; tests verify initial idle/pending and empty states in server-rendered output within QueryClientProvider. (≤50 words)

Changes

Cohort / File(s) Summary
SSR Mutation Hook Tests
packages/react-query/src/__tests__/ssr.test.tsx
Adds server-side rendering tests: a useMutation-based Page asserting initial isIdle / isPending states in SSR markup, and a useMutationState-based Page asserting the mutation state array is initially empty.
Public API Exports
packages/react-query/src/index.ts (or package root exports)
Adds useMutation and useMutationState to the package's public/root exports so they are importable from the package entry point.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • manudeli

Poem

🐰
I hopped through tests both swift and neat,
SSR pages found mutation states complete.
Idle and empty—no surprises here,
A tiny cheer from a rabbit near! 🥕

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding SSR tests for useMutation and useMutationState hooks to the test file.
Description check ✅ Passed The description follows the template with all required sections completed: Changes section explains what was added, Checklist is fully checked, and Release Impact correctly identifies this as dev-only.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 633a2e4 and e72096f.

📒 Files selected for processing (1)
  • packages/react-query/src/__tests__/ssr.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/react-query/src/tests/ssr.test.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Preview
  • GitHub Check: Test

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

@nx-cloud
Copy link

nx-cloud bot commented Dec 28, 2025

View your CI Pipeline Execution ↗ for commit e72096f

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

☁️ Nx Cloud last updated this comment at 2025-12-28 06:53:06 UTC

@sukvvon sukvvon force-pushed the test/react-query-ssr-mutation branch from 95ae247 to 633a2e4 Compare December 28, 2025 06:45
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 28, 2025

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: e72096f

@sukvvon sukvvon force-pushed the test/react-query-ssr-mutation branch from 633a2e4 to e72096f Compare December 28, 2025 06:48
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: 0

🧹 Nitpick comments (1)
packages/react-query/src/__tests__/ssr.test.tsx (1)

205-219: LGTM! Test correctly verifies useMutationState SSR behavior.

The test properly validates that useMutationState returns an empty array during server-side rendering.

Optional: Add queryCache.clear() for consistency

For consistency with other tests in this file, consider adding queryCache.clear() at the end of both new test cases, even though mutations don't create cache entries:

    expect(markup).toContain('mutationState: 0')
+
+   queryCache.clear()
  })

Apply the same to the useMutation test at line 203.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5810292 and 633a2e4.

📒 Files selected for processing (1)
  • packages/react-query/src/__tests__/ssr.test.tsx
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-22T09:06:05.219Z
Learnt from: sukvvon
Repo: TanStack/query PR: 9892
File: packages/solid-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx:331-335
Timestamp: 2025-11-22T09:06:05.219Z
Learning: In TanStack/query test files, when a queryFn contains side effects (e.g., setting flags for test verification), prefer async/await syntax for clarity; when there are no side effects, prefer the .then() pattern for conciseness.

Applied to files:

  • packages/react-query/src/__tests__/ssr.test.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Test
  • GitHub Check: Preview
🔇 Additional comments (2)
packages/react-query/src/__tests__/ssr.test.tsx (2)

10-11: LGTM!

The imports are correctly added for the new mutation hook tests.


179-203: LGTM! Test correctly verifies useMutation SSR behavior.

The test properly validates that useMutation returns the expected idle state during server-side rendering. The assertions confirm the correct initial state without triggering the mutation function.

@codecov
Copy link

codecov bot commented Dec 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.45%. Comparing base (f64ac77) to head (e72096f).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #9995       +/-   ##
===========================================
+ Coverage   45.89%   84.45%   +38.55%     
===========================================
  Files         200       26      -174     
  Lines        8437      373     -8064     
  Branches     1933      108     -1825     
===========================================
- Hits         3872      315     -3557     
+ Misses       4116       49     -4067     
+ Partials      449        9      -440     
Components Coverage Δ
@tanstack/angular-query-experimental ∅ <ø> (∅)
@tanstack/eslint-plugin-query ∅ <ø> (∅)
@tanstack/query-async-storage-persister ∅ <ø> (∅)
@tanstack/query-broadcast-client-experimental ∅ <ø> (∅)
@tanstack/query-codemods ∅ <ø> (∅)
@tanstack/query-core ∅ <ø> (∅)
@tanstack/query-devtools ∅ <ø> (∅)
@tanstack/query-persist-client-core ∅ <ø> (∅)
@tanstack/query-sync-storage-persister ∅ <ø> (∅)
@tanstack/query-test-utils ∅ <ø> (∅)
@tanstack/react-query 97.00% <ø> (+0.99%) ⬆️
@tanstack/react-query-devtools 9.25% <ø> (ø)
@tanstack/react-query-next-experimental ∅ <ø> (∅)
@tanstack/react-query-persist-client 100.00% <ø> (ø)
@tanstack/solid-query ∅ <ø> (∅)
@tanstack/solid-query-devtools ∅ <ø> (∅)
@tanstack/solid-query-persist-client ∅ <ø> (∅)
@tanstack/svelte-query ∅ <ø> (∅)
@tanstack/svelte-query-devtools ∅ <ø> (∅)
@tanstack/svelte-query-persist-client ∅ <ø> (∅)
@tanstack/vue-query ∅ <ø> (∅)
@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.

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