Skip to content

fix(query-core): set dataUpdatedAt for streamed queries that resolve before hydration (#10603)#10895

Open
ousamabenyounes wants to merge 1 commit into
TanStack:mainfrom
ousamabenyounes:fix/streamed-query-dataupdatedat
Open

fix(query-core): set dataUpdatedAt for streamed queries that resolve before hydration (#10603)#10895
ousamabenyounes wants to merge 1 commit into
TanStack:mainfrom
ousamabenyounes:fix/streamed-query-dataupdatedat

Conversation

@ousamabenyounes
Copy link
Copy Markdown
Contributor

@ousamabenyounes ousamabenyounes commented Jun 6, 2026

Fixes #10603

Summary

When a dehydrated pending query's promise resolves synchronously during hydration (e.g., a React streamed query that completed before the client hydrated), the query correctly transitions to success but dataUpdatedAt remained 0.

This happened because PR #10444 removed the unnecessary query.fetch() call for already-resolved promises — which was correct for avoiding unnecessary fetch setup, but it also removed the side effect that set dataUpdatedAt.

Fix

The fix sets dataUpdatedAt to Date.now() in the hydration path when:

  • The dehydrated query was pending (status: 'pending')
  • It resolved to have data (data !== undefined)
  • dataUpdatedAt is 0 (its default for pending queries that never completed on the server)

This applies to both:

  1. New queries — when a query is built from the dehydrated state (the else branch)
  2. Existing queries — when updating a query already in the cache (the if branch)

Testing

Added two test cases:

  • New query: verifies dataUpdatedAt > 0 after hydrating a resolved pending query
  • Existing query: verifies same for queries already in the cache

Summary by CodeRabbit

  • Bug Fixes

    • Query timestamp metadata is now correctly updated during streamed query rehydration with synchronously resolved data.
  • Tests

    • Added test coverage for streamed query rehydration scenarios.

…before hydration (TanStack#10603)

When a dehydrated pending query's promise resolves synchronously
during hydration (e.g., a React streamed query that completed before
the client hydrated), the query correctly transitions to 'success' but
dataUpdatedAt remained 0. This happened because PR TanStack#10444 removed the
unnecessary query.fetch() call that previously set it.

The fix sets dataUpdatedAt to Date.now() in the hydration path when:
- The dehydrated query was pending (status: 'pending')
- It resolved to have data (data !== undefined)
- dataUpdatedAt is 0 (its default for pending queries)

This applies to both new queries and existing queries in the cache.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 6, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e7eeecf1-1f7c-47ce-9e71-35d911a37500

📥 Commits

Reviewing files that changed from the base of the PR and between ba7fbc4 and 65d79ae.

📒 Files selected for processing (3)
  • .changeset/streamed-query-dataupdatedat.md
  • packages/query-core/src/__tests__/hydration.test.tsx
  • packages/query-core/src/hydration.ts

📝 Walkthrough

Walkthrough

This PR fixes a bug where dataUpdatedAt remained 0 when hydrating pending streamed queries that resolved synchronously before hydration. The fix normalizes dataUpdatedAt to Date.now() in hydration when the value is missing, and adds test coverage for both new and existing query scenarios.

Changes

Streamed Query Hydration dataUpdatedAt Fix

Layer / File(s) Summary
Streamed query hydration dataUpdatedAt normalization
packages/query-core/src/hydration.ts
When hydrating a query with resolved data but dataUpdatedAt of 0, the function now sets dataUpdatedAt to Date.now() in both the existing query update path and the new query restoration path.
Test coverage for pending query hydration scenarios
packages/query-core/src/__tests__/hydration.test.tsx
Two tests verify that rehydrating a pending query that resolved before hydration results in status: success with dataUpdatedAt > 0, covering new query and existing pending query cases.
Changeset documentation
.changeset/streamed-query-dataupdatedat.md
Release notes entry documents the bug fix for @tanstack/query-core.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A timestamp was lost in the hydration stream,
Left at zero—a developer's bad dream!
But now when queries resolve before their due,
dataUpdatedAt springs forth anew.
The rabbit hops through tests, both old and new,
And cheers the fix that makes timestamps true! 🐇✨

🚥 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 clearly and concisely describes the main fix: setting dataUpdatedAt for streamed queries that resolve before hydration, directly addressing issue #10603.
Description check ✅ Passed The description comprehensively covers the bug summary, root cause from PR #10444, the fix implementation details, and testing approach. It follows the template structure with clear sections.
Linked Issues check ✅ Passed The PR fully addresses issue #10603 by setting dataUpdatedAt to Date.now() during hydration for pending queries that resolved before hydration, with comprehensive test coverage.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the dataUpdatedAt issue: a changeset, two focused test cases, and hydration logic updates with no unrelated modifications.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dataUpdatedAt incorrect for streamed queries that resolve before hydration

1 participant