Skip to content

Conversation

sukvvon
Copy link
Contributor

@sukvvon sukvvon commented Sep 2, 2025

Summary by CodeRabbit

  • Tests
    • Strengthened mutation state coverage with sequence tracking across renders.
    • Adjusted timer advances to better reflect batching behavior.
    • Expanded assertions to validate intermediate states and full mutation sequences.
    • Ensured components render before timers advance for more reliable outcomes.
    • Refined assertion styles for clearer intent and readability.
    • Minor JSX/formatting cleanups within test setups.

Copy link

coderabbitai bot commented Sep 2, 2025

Walkthrough

Test updates in packages/react-query/src/tests/useMutationState.test.tsx adjust timer advances, render timing, and assertions to capture mutation states over time. An array now records isMutating values per render, and tests validate intermediate and final sequences. Minor JSX formatting and assertion style updates are included.

Changes

Cohort / File(s) Summary
Test adjustments for mutation sequencing
packages/react-query/src/__tests__/useMutationState.test.tsx
Record isMutating on each render; adjust timer advances (41ms, remove 1ms); assert intermediate indices and full sequence [0, 1, 2, 1, 0]; render Page before advancing timers; minor JSX cleanup; switch some assertions to toBeInTheDocument(); ensure mounting in custom queryClient test.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

package: react-query

Suggested reviewers

  • manudeli

Poem

In burrows of tests, I thump with delight,
Arrays of mutates hop left and right.
Forty-one ticks, then none to spare—
I sniff each render’s stateful air.
From zero to two, then gently back,
A bunny approves this tidy track. 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

nx-cloud bot commented Sep 2, 2025

View your CI Pipeline Execution ↗ for commit 79b9ebf

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

☁️ Nx Cloud last updated this comment at 2025-09-03 01:39:19 UTC

Copy link

pkg-pr-new bot commented Sep 2, 2025

More templates

@tanstack/angular-query-devtools-experimental

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

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 79b9ebf

Copy link

codecov bot commented Sep 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.51%. Comparing base (c75a994) to head (79b9ebf).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #9611       +/-   ##
===========================================
+ Coverage   45.26%   84.51%   +39.24%     
===========================================
  Files         208       26      -182     
  Lines        8340      368     -7972     
  Branches     1895      108     -1787     
===========================================
- Hits         3775      311     -3464     
+ Misses       4118       48     -4070     
+ Partials      447        9      -438     
Components Coverage Δ
@tanstack/angular-query-devtools-experimental ∅ <ø> (∅)
@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 96.00% <ø> (ø)
@tanstack/react-query-devtools 10.00% <ø> (ø)
@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

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/react-query/src/__tests__/useMutationState.test.tsx (1)

62-76: Use prefix/suffix assertions instead of exact sequence to prevent flaky tests

-    await vi.advanceTimersByTimeAsync(41)
-    expect(isMutatingArray[0]).toEqual(0)
-    expect(isMutatingArray[1]).toEqual(1)
-    expect(isMutatingArray[2]).toEqual(2)
-    expect(isMutatingArray[3]).toEqual(1)
-    expect(isMutatingArray[4]).toEqual(0)
-
-    expect(isMutatingArray).toEqual([0, 1, 2, 1, 0])
+    await vi.advanceTimersByTimeAsync(41)
+    // Deterministic prefix/suffix; allow batching differences in the middle.
+    expect(isMutatingArray.slice(0, 3)).toEqual([0, 1, 2])
+    expect([4, 5]).toContain(isMutatingArray.length)
+    expect(isMutatingArray.at(-1)).toEqual(0)
🧹 Nitpick comments (1)
packages/react-query/src/__tests__/useMutationState.test.tsx (1)

21-27: Avoid side-effects in render; record values in an effect

Pushing to a shared array during render is a side-effect and can behave unexpectedly (e.g., extra renders). Record on value change via an effect instead.

 function IsMutating() {
   const isMutating = useIsMutating()
-
-  isMutatingArray.push(isMutating)
-
-  return null
+  React.useEffect(() => {
+    isMutatingArray.push(isMutating)
+  }, [isMutating])
+  return null
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0a35234 and 84f819e.

📒 Files selected for processing (1)
  • packages/react-query/src/__tests__/useMutationState.test.tsx (7 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/react-query/src/__tests__/useMutationState.test.tsx (2)
packages/vue-query/src/queryClient.ts (1)
  • isMutating (53-55)
packages/query-core/src/queryClient.ts (1)
  • isMutating (116-120)
⏰ 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
🔇 Additional comments (2)
packages/react-query/src/__tests__/useMutationState.test.tsx (2)

173-177: LGTM: custom queryClient path

Using the queryClient param with plain render (no Provider) is correct, and the assertion reads clearly.


230-235: LGTM: clearer presence assertions

Switch to toBeInTheDocument() improves intent without changing semantics.

@TkDodo TkDodo merged commit 43049c5 into TanStack:main Sep 3, 2025
8 checks passed
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.

2 participants