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: useMutation and useMutationState.
  • Tests

    • Added server-side rendering tests for mutation hooks confirming initial idle/pending status 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: 4f1763c

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 assert initial idle/pending and empty mutation-state 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 in SSR markup, and a useMutationState-based Page asserting 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.

Sequence Diagram(s)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • manudeli
  • TkDodo

Poem

🐰
I hopped through tests both swift and neat,
SSR pages found mutation states complete.
Idle and empty, quiet as a seed,
A tiny cheer for every passing feed. πŸ₯•

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 PR title accurately describes the main change: adding SSR tests for useMutation and useMutationState hooks, which aligns with the actual code modifications.
Description check βœ… Passed The PR description follows the required template with all sections completed: Changes section describes what was added, Checklist is fully checked, and Release Impact correctly identifies this as dev-only with no changeset needed.
✨ 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 1dc32f0 and b886a33.

πŸ“’ 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: Test
  • GitHub Check: Preview

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 4f1763c

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... βœ… Succeeded 3m 12s View β†—
nx run-many --target=build --exclude=examples/*... βœ… Succeeded 1s View β†—

☁️ Nx Cloud last updated this comment at 2025-12-29 12:23:42 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: 4f1763c

@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.71%. Comparing base (e907f89) to head (4f1763c).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #9995       +/-   ##
===========================================
+ Coverage   45.79%   84.71%   +38.92%     
===========================================
  Files         200       26      -174     
  Lines        8520      373     -8147     
  Branches     1975      110     -1865     
===========================================
- Hits         3902      316     -3586     
+ Misses       4158       48     -4110     
+ Partials      460        9      -451     
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.34% <ΓΈ> (+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.

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

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

212-218: Consider verifying additional mutation state properties.

While checking the status is sufficient for SSR testing, you could enhance test coverage by also verifying the isIdle and isPending properties explicitly, similar to how other tests verify multiple aspects of the query/mutation state.

πŸ”Ž Optional enhancement for more comprehensive coverage
    function Page() {
      const mutation = useMutation({
        mutationFn: () => sleep(10).then(() => 'data'),
      })

-     return <div>{`status: ${mutation.status}`}</div>
+     return (
+       <div>
+         {`status: ${mutation.status}, isIdle: ${mutation.isIdle}, isPending: ${mutation.isPending}`}
+       </div>
+     )
    }

    const markup = renderToString(
      <QueryClientProvider client={queryClient}>
        <Page />
      </QueryClientProvider>,
    )

    expect(markup).toContain('status: idle')
+   expect(markup).toContain('isIdle: true')
+   expect(markup).toContain('isPending: false')
πŸ“œ Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between e72096f and 1dc32f0.

πŸ“’ 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 (1)
packages/react-query/src/__tests__/ssr.test.tsx (1)

11-12: LGTM! Import additions are appropriate.

The new imports for useMutation and useMutationState are correctly added and consistent with the existing import pattern in the file.

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