Skip to content

Conversation

@sukvvon
Copy link
Contributor

@sukvvon sukvvon commented Dec 28, 2025

🎯 Changes

Add useIsFetching test 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

    • useIsFetching hook is now exported from the public API and available for use.
  • Tests

    • Added server-side rendering test coverage for useIsFetching to validate fetching state behavior.

✏️ 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: 29aa8fb

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

A new SSR test case was added to validate the useIsFetching hook behavior after query prefetching in server-side rendering. The test imports useIsFetching into the public API usage and verifies that the fetching state correctly reflects zero after a prefetch operation completes.

Changes

Cohort / File(s) Summary
SSR Test Updates
packages/react-query/src/__tests__/ssr.test.tsx
Added import of useIsFetching hook from public API; introduced new test case that creates a Page component using useQuery and useIsFetching, prefetches a query, renders to string, and asserts that the rendered output contains data and isFetching equals 0 after prefetch completes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A fetch hook now dances in SSR's light,
useIsFetching tested, the state burns bright,
Prefetch, render, assertβ€”all done just right,
Queries hop forward through the server's night! ✨

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 clearly and specifically describes the main change: adding a useIsFetching test for SSR scenarios.
Description check βœ… Passed The description follows the template with all required sections completed, including changes, checklist items marked, and release impact clarification.
✨ Finishing touches
  • πŸ“ Generate docstrings
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 29aa8fb

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

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

@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@9994

@tanstack/eslint-plugin-query

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 29aa8fb

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)

178-207: Excellent test coverage for useIsFetching in SSR!

The test correctly validates that useIsFetching returns 0 after a prefetch completes in server-side rendering. The logic follows the established pattern: prefetch β†’ wait β†’ render β†’ assert.

Consider wrapping queryFn with vi.fn() for consistency with similar tests (lines 33, 78, 141) and to add a call-count assertion:

Optional refactor for consistency
-    const queryFn = () => sleep(10).then(() => 'data')
+    const queryFn = vi.fn(() => sleep(10).then(() => 'data'))

Then add after line 204:

     expect(markup).toContain('data')
     expect(markup).toContain('isFetching: 0')
+    expect(queryFn).toHaveBeenCalledTimes(1)

This would verify that the query was prefetched exactly once and not re-fetched during render.

πŸ“œ 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 29aa8fb.

πŸ“’ 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)

10-10: LGTM! Clean import addition.

The useIsFetching import is correctly placed and necessary for the new test case.

@codecov
Copy link

codecov bot commented Dec 28, 2025

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 83.91%. Comparing base (f64ac77) to head (29aa8fb).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #9994       +/-   ##
===========================================
+ Coverage   45.89%   83.91%   +38.02%     
===========================================
  Files         200       26      -174     
  Lines        8437      373     -8064     
  Branches     1933      110     -1823     
===========================================
- Hits         3872      313     -3559     
+ Misses       4116       51     -4065     
+ 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 96.34% <ΓΈ> (+0.33%) ⬆️
@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.

@TkDodo TkDodo merged commit 642f72d into TanStack:main Dec 28, 2025
9 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