Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@976520
Copy link
Contributor

@976520 976520 commented Jan 29, 2026

🎯 Changes

Fixes #9978

Recreate the query promise when a retry transitions the query to fetching, ensuring useQuery().promise provides a fresh pending promise to Suspense.

Explicitly refetch errored queries on QueryErrorResetBoundary reset, even when useQuery is outside the ErrorBoundary.

Limit refetching to active and enabled queries to avoid unintended retries.

✅ 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

    • Error reset boundary now integrates with the query client to automatically refetch failed queries when reset, smoothing error recovery.
  • Bug Fixes

    • Improved handling of rejected query states to ensure pending fetches and retries transition consistently after errors.
  • Tests

    • Added test coverage for promise-based query handling with error-boundary reset and retry scenarios.

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

@changeset-bot
Copy link

changeset-bot bot commented Jan 29, 2026

⚠️ No Changeset found

Latest commit: 00af302

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 Jan 29, 2026

📝 Walkthrough

Walkthrough

This PR adjusts thenable lifecycle in QueryObserver to recreate the pending thenable when a rejected result transitions to a fetch-in-progress, and extends QueryErrorResetBoundary to accept/use a QueryClient to trigger refetches on reset. A new test verifies retry behavior for useQuery().promise with QERB.

Changes

Cohort / File(s) Summary
QueryObserver thenable lifecycle
packages/query-core/src/queryObserver.ts
Recreate the internal pending thenable not only on error-without-data mismatches but also when the next result's fetchStatus is 'fetching', widening conditions for a fresh thenable after rejection.
QueryErrorResetBoundary behavior
packages/react-query/src/QueryErrorResetBoundary.tsx
Added exported QueryErrorClearResetFunction; createValue now accepts optional QueryClient; component uses useQueryClient() and invokes client.refetchQueries() during reset to refetch errored/enabled queries with observers.
Public re-exports
packages/query-core/src/index.ts
Added export: resolveEnabled re-exported from ./utils.
Tests
packages/react-query/src/__tests__/useQuery.promise.test.tsx
Added test(s) asserting that QueryErrorResetBoundary-triggered reset retries queries when useQuery().promise is used and the ErrorBoundary/QERB are in the same component (duplicate test blocks present in diff).

Sequence Diagram(s)

sequenceDiagram
  participant Component
  participant ErrorBoundary
  participant QERB as QueryErrorResetBoundary
  participant Client as QueryClient
  participant Observer as QueryObserver
  participant Server

  Component->>Observer: subscribe / read promise (useQuery().promise)
  Observer->>Server: fetch -> returns error
  Observer-->>Component: throws (suspense/error)
  Component->>ErrorBoundary: shows error UI
  ErrorBoundary->>QERB: resetErrorBoundary() / onReset
  QERB->>Client: refetchQueries(predicate)
  Client->>Observer: trigger refetch
  Observer->>Server: fetch -> returns data
  Observer-->>Component: resolves promise with data
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • TkDodo

Poem

🐰
A hiccup hops, the promise fell,
I nudge the client, ring the bell,
Refetching carrots, fresh and bright,
Thenables bloom again in light,
Retry! — the meadow cheers tonight. 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing useQuery().promise to retry correctly on error boundary reset, which is the core objective of this PR.
Description check ✅ Passed The description covers the key changes, references the linked issue (#9978), includes all checklist items completed, and provides adequate detail about the fix's scope and implementation approach.
Linked Issues check ✅ Passed The PR fully addresses issue #9978 by recreating the query promise on fetching transitions, explicitly refetching errored queries on reset, and limiting refetching to active/enabled queries as required.
Out of Scope Changes check ✅ Passed All changes directly support the core objective: the QueryObserver change handles promise recreation, QueryErrorResetBoundary implements explicit refetching, the test validates the fix, and the export of resolveEnabled supports the utility needs.

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

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@nx-cloud
Copy link

nx-cloud bot commented Jan 29, 2026

View your CI Pipeline Execution ↗ for commit 00af302

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

☁️ Nx Cloud last updated this comment at 2026-01-29 09:12:57 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 29, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 00af302

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: 1

🤖 Fix all issues with AI agents
In `@packages/react-query/src/QueryErrorResetBoundary.tsx`:
- Around line 26-33: The predicate used in client?.refetchQueries incorrectly
treats observer.options.enabled functions as truthy; update the predicate to
resolve the enabled state using resolveEnabled from query-core (same approach as
in query.ts:270) so the check becomes something like resolving
observer.options.enabled against the query and comparing to !== false before
counting it as enabled; modify the predicate passed to refetchQueries where
query, observer, and observer.options.enabled are referenced and import/use
resolveEnabled to properly evaluate callback-based enabled options.
🧹 Nitpick comments (1)
packages/react-query/src/QueryErrorResetBoundary.tsx (1)

61-62: Consider potential stale closure with QueryClient.

The useState initializer captures the client reference at mount time. While the QueryClient instance is typically stable throughout an app's lifecycle, if it were to change (e.g., during testing or in edge cases), the value.reset() would continue using the original client.

This is likely acceptable given typical usage patterns, but worth noting for awareness.

@sentry
Copy link

sentry bot commented Jan 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 42.74%. Comparing base (ed5e5fc) to head (00af302).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #10079      +/-   ##
==========================================
+ Coverage   36.87%   42.74%   +5.87%     
==========================================
  Files         245      172      -73     
  Lines       11103     8267    -2836     
  Branches     2083     1687     -396     
==========================================
- Hits         4094     3534     -560     
+ Misses       6484     4343    -2141     
+ Partials      525      390     -135     
Components Coverage Δ
@tanstack/angular-query-experimental 46.35% <ø> (ø)
@tanstack/eslint-plugin-query ∅ <ø> (∅)
@tanstack/query-async-storage-persister 43.85% <ø> (ø)
@tanstack/query-broadcast-client-experimental 24.39% <ø> (ø)
@tanstack/query-codemods ∅ <ø> (∅)
@tanstack/query-core 75.58% <100.00%> (+0.03%) ⬆️
@tanstack/query-devtools 3.38% <ø> (ø)
@tanstack/query-persist-client-core 80.12% <ø> (ø)
@tanstack/query-sync-storage-persister 84.61% <ø> (ø)
@tanstack/query-test-utils ∅ <ø> (∅)
@tanstack/react-query 29.38% <100.00%> (+0.38%) ⬆️
@tanstack/react-query-devtools 9.25% <ø> (ø)
@tanstack/react-query-next-experimental ∅ <ø> (∅)
@tanstack/react-query-persist-client 100.00% <ø> (ø)
@tanstack/solid-query 53.52% <ø> (ø)
@tanstack/solid-query-devtools 64.17% <ø> (ø)
@tanstack/solid-query-persist-client 100.00% <ø> (ø)
@tanstack/svelte-query ∅ <ø> (∅)
@tanstack/svelte-query-devtools ∅ <ø> (∅)
@tanstack/svelte-query-persist-client ∅ <ø> (∅)
@tanstack/vue-query 35.67% <ø> (ø)
@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.

experimental_prefetchInRender does not work with useQueryErrorResetBoundary

1 participant