Skip to content

Conversation

@TkDodo
Copy link
Collaborator

@TkDodo TkDodo commented Nov 5, 2025

🎯 Changes

βœ… 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

  • Bug Fixes
    • Fixed unhandled promise rejections when dehydrating pending queries during server-side rendering.

@TkDodo TkDodo requested a review from Ephem November 5, 2025 13:30
@changeset-bot
Copy link

changeset-bot bot commented Nov 5, 2025

πŸ¦‹ Changeset detected

Latest commit: 033c868

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 19 packages
Name Type
@tanstack/query-core Patch
@tanstack/angular-query-experimental Patch
@tanstack/query-async-storage-persister Patch
@tanstack/query-broadcast-client-experimental Patch
@tanstack/query-persist-client-core Patch
@tanstack/query-sync-storage-persister Patch
@tanstack/react-query Patch
@tanstack/solid-query Patch
@tanstack/svelte-query Patch
@tanstack/vue-query Patch
@tanstack/angular-query-persist-client Patch
@tanstack/react-query-persist-client Patch
@tanstack/solid-query-persist-client Patch
@tanstack/svelte-query-persist-client Patch
@tanstack/react-query-devtools Patch
@tanstack/react-query-next-experimental Patch
@tanstack/solid-query-devtools Patch
@tanstack/svelte-query-devtools Patch
@tanstack/vue-query-devtools Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 5, 2025

Walkthrough

Introduces a changeset documenting a patch fix for @tanstack/query-core that wraps promise chains in dehydration with a no-op catch handler to suppress unhandled rejections on pending queries.

Changes

Cohort / File(s) Summary
Changeset documentation
.changeset/little-berries-search.md
Adds patch release notes documenting the fix for unhandled rejections on dehydrated promises
Hydration promise handling
packages/query-core/src/hydration.ts
Refactors dehydration logic to wrap pending query promises in a dehydratePromise function with a local catch(noop) to suppress unhandled rejections while preserving correct result propagation

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12–15 minutes

  • Verify the dehydratePromise wrapper function correctly handles promise chains without introducing regressions
  • Confirm the no-op catch handler doesn't mask legitimate errors or alter promise resolution behavior
  • Check that dehydrated query results still propagate correctly through the cache

Possibly related PRs

Poem

🐰 A promise once scattered and wild,
Now wrapped with a catch, gentle and mild,
No rejections left crying at night,
The hydration flows smoothβ€”what a sight!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description uses the correct template structure but lacks actual content in the 'Changes' section and all checklist items remain unchecked, including the required changeset generation. Fill in the 'Changes' section with details about the fix and its motivation, and ensure checklist items (especially changeset generation) are properly completed and checked.
βœ… Passed checks (1 passed)
Check name Status Explanation
Title check βœ… Passed The title clearly and specifically describes the main change: only attaching .then and .catch callbacks to promises during dehydration, which aligns with the refactoring in hydration.ts.
✨ Finishing touches
  • πŸ“ Generate docstrings
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/no-promise-dehydrate

πŸ“œ Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between a5fca0e and 033c868.

πŸ“’ Files selected for processing (2)
  • .changeset/little-berries-search.md (1 hunks)
  • packages/query-core/src/hydration.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (3)
πŸ““ Common learnings
Learnt from: TkDodo
Repo: TanStack/query PR: 9612
File: packages/query-async-storage-persister/src/asyncThrottle.ts:0-0
Timestamp: 2025-09-02T17:57:33.184Z
Learning: When importing from tanstack/query-core in other TanStack Query packages like query-async-storage-persister, a workspace dependency "tanstack/query-core": "workspace:*" needs to be added to the package.json.
πŸ“š Learning: 2025-11-02T22:52:33.071Z
Learnt from: DogPawHat
Repo: TanStack/query PR: 9835
File: packages/query-core/src/__tests__/queryClient.test-d.tsx:242-256
Timestamp: 2025-11-02T22:52:33.071Z
Learning: In the TanStack Query codebase, the new `query` and `infiniteQuery` methods support the `select` option for data transformation, while the legacy `fetchQuery` and `fetchInfiniteQuery` methods do not support `select` and should reject it at the type level.

Applied to files:

  • packages/query-core/src/hydration.ts
πŸ“š Learning: 2025-09-02T17:57:33.184Z
Learnt from: TkDodo
Repo: TanStack/query PR: 9612
File: packages/query-async-storage-persister/src/asyncThrottle.ts:0-0
Timestamp: 2025-09-02T17:57:33.184Z
Learning: When importing from tanstack/query-core in other TanStack Query packages like query-async-storage-persister, a workspace dependency "tanstack/query-core": "workspace:*" needs to be added to the package.json.

Applied to files:

  • .changeset/little-berries-search.md
🧬 Code graph analysis (1)
packages/query-core/src/hydration.ts (2)
packages/query-core/src/query.ts (1)
  • promise (198-200)
packages/query-core/src/utils.ts (1)
  • noop (82-82)
πŸ”‡ Additional comments (3)
packages/query-core/src/hydration.ts (2)

82-104: LGTM! Clean encapsulation of promise handling.

The dehydratePromise wrapper correctly:

  • Chains serialization via .then(serializeData)
  • Preserves error redaction logic with appropriate logging in development
  • Adds catch(noop) to suppress unhandled rejections while allowing the rejection to propagate to the query cache

This ensures promise handlers are only attached during dehydration, aligning with the PR objective.


116-118: LGTM! Correctly scoped promise dehydration.

The conditional application of dehydratePromise() only when query.state.status === 'pending' ensures promise handlers are attached only when needed, preventing unnecessary overhead and potential unhandled rejection warnings in non-dehydration scenarios.

.changeset/little-berries-search.md (1)

1-5: LGTM! Changeset correctly documents the fix.

The changeset appropriately declares a patch release for @tanstack/query-core with a description that matches the PR objective.


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

@nx-cloud
Copy link

nx-cloud bot commented Nov 5, 2025

View your CI Pipeline Execution β†— for commit 033c868

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

☁️ Nx Cloud last updated this comment at 2025-11-05 15:32:51 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 5, 2025

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 033c868

@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

Sizes for commit 033c868:

Branch Bundle Size
Main
This PR

@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 59.79%. Comparing base (a5fca0e) to head (033c868).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #9847       +/-   ##
===========================================
+ Coverage   45.75%   59.79%   +14.04%     
===========================================
  Files         200      129       -71     
  Lines        8408     5624     -2784     
  Branches     1929     1525      -404     
===========================================
- Hits         3847     3363      -484     
+ Misses       4113     1956     -2157     
+ Partials      448      305      -143     
Components Coverage Ξ”
@tanstack/angular-query-experimental 93.85% <ΓΈ> (ΓΈ)
@tanstack/eslint-plugin-query βˆ… <ΓΈ> (βˆ…)
@tanstack/query-async-storage-persister 43.85% <ΓΈ> (ΓΈ)
@tanstack/query-broadcast-client-experimental 24.39% <ΓΈ> (ΓΈ)
@tanstack/query-codemods βˆ… <ΓΈ> (βˆ…)
@tanstack/query-core 97.38% <100.00%> (+<0.01%) ⬆️
@tanstack/query-devtools 3.48% <ΓΈ> (ΓΈ)
@tanstack/query-persist-client-core 80.00% <ΓΈ> (ΓΈ)
@tanstack/query-sync-storage-persister 84.61% <ΓΈ> (ΓΈ)
@tanstack/query-test-utils βˆ… <ΓΈ> (βˆ…)
@tanstack/react-query 96.01% <ΓΈ> (ΓΈ)
@tanstack/react-query-devtools 10.00% <ΓΈ> (ΓΈ)
@tanstack/react-query-next-experimental βˆ… <ΓΈ> (βˆ…)
@tanstack/react-query-persist-client 100.00% <ΓΈ> (ΓΈ)
@tanstack/solid-query 77.81% <ΓΈ> (ΓΈ)
@tanstack/solid-query-devtools 61.90% <ΓΈ> (ΓΈ)
@tanstack/solid-query-persist-client 100.00% <ΓΈ> (ΓΈ)
@tanstack/svelte-query βˆ… <ΓΈ> (βˆ…)
@tanstack/svelte-query-devtools βˆ… <ΓΈ> (βˆ…)
@tanstack/svelte-query-persist-client βˆ… <ΓΈ> (βˆ…)
@tanstack/vue-query 71.10% <ΓΈ> (ΓΈ)
@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 marked this pull request as ready for review November 5, 2025 15:30
Ensure .then and .catch are only attached to dehydrated promises.
@Svish
Copy link
Contributor

Svish commented Nov 5, 2025

@TkDodo Re request to try this out, I reverted our project to before I removed the cancellation token thing, and was able to get the same errors in the log. I then installed the preview-version from this PR, and as far as I can see, it seems there are no longer any errors in the log. So, from my point of view at least, this PR seems to fix the issue. πŸ‘

@TkDodo TkDodo merged commit b4cd121 into main Nov 5, 2025
9 checks passed
@TkDodo TkDodo deleted the feature/no-promise-dehydrate branch November 5, 2025 15:44
@github-actions github-actions bot mentioned this pull request Nov 5, 2025
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.

3 participants