⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
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

  • Tests

    • Added server-side rendering tests for mutation hooks to confirm initial idle status and that mutation state is empty in server-rendered output.
  • Chores

    • No changes to public APIs or exported interfaces.

✏️ 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: 3e69170

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 two server-side rendering tests that render components using useMutation and useMutationState and assert the server-rendered markup shows the initial idle status and an empty mutation-state array. No runtime code or public API was modified. (≤50 words)

Changes

Cohort / File(s) Summary
SSR Mutation Hook Tests
packages/react-query/src/__tests__/ssr.test.tsx
Adds two SSR tests: one rendering a Page that uses useMutation and asserting the SSR markup contains status: idle; another rendering a Page that uses useMutationState and asserting the SSR markup contains mutationState: 0.

Sequence Diagram(s)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • manudeli

Poem

🐇
I hopped into tests where mutations hide,
Found idle hearts and empty arrays inside.
Server-rendered whispers, calm and neat,
A little carrot clap for tests complete. 🥕

🚥 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 accurately describes the main change: adding useMutation and useMutationState tests for SSR, which matches the file modifications and test additions in the changeset.
Description check ✅ Passed The description follows the template structure with all required sections completed: Changes section describes the additions, Checklist items are marked (both boxes checked), and Release Impact clearly indicates this is dev-only with no release needed.

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

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b886a33 and 3e69170.

📒 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 3e69170

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

☁️ Nx Cloud last updated this comment at 2026-01-11 08:53:35 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: 3e69170

@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 85.18%. Comparing base (44c3cb9) to head (3e69170).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #9995       +/-   ##
===========================================
+ Coverage   45.84%   85.18%   +39.34%     
===========================================
  Files         200       26      -174     
  Lines        8525      378     -8147     
  Branches     1968      111     -1857     
===========================================
- Hits         3908      322     -3586     
+ Misses       4157       47     -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.71% <ø> (+0.98%) ⬆️
@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