Skip to content

feat(query-core): allow overriding dehydration timestamp 🤖🤖🤖 - #11395

Draft
aurorascharff wants to merge 1 commit into
TanStack:mainfrom
aurorascharff:codex/configurable-dehydrated-at
Draft

feat(query-core): allow overriding dehydration timestamp 🤖🤖🤖#11395
aurorascharff wants to merge 1 commit into
TanStack:mainfrom
aurorascharff:codex/configurable-dehydrated-at

Conversation

@aurorascharff

@aurorascharff aurorascharff commented Sep 4, 2026

Copy link
Copy Markdown

🎯 Changes

Next.js Cache Components cannot prerender dehydrate() because dehydrateQuery() reads Date.now().

The Next.js client-side fetching guide works around this by caching a timestamp with the same tags as the data, then manually mapping the query cache into a DehydratedState:

const updatedAt = await getHydrationUpdatedAt(tags)

queryClient.setQueryData(queryKey, data, { updatedAt })

return {
  mutations: [],
  queries: queryClient.getQueryCache().getAll().map((query) => ({
    dehydratedAt: updatedAt,
    queryHash: query.queryHash,
    queryKey: query.queryKey,
    state: query.state,
  })),
}

This PR adds dehydratedAt to DehydrateOptions, so applications can use the normal dehydration logic instead:

return dehydrate(queryClient, { dehydratedAt: updatedAt })

The caller is still responsible for keeping the timestamp in the same cache lifecycle as the data. When omitted, dehydratedAt continues to default to Date.now().

Includes tests, documentation, and a query-core changeset. Related to #9457.

✅ Checklist

  • I have followed the steps in the Contributing Guide
  • I have tested the code changes locally with pnpm run test:pr, or does not apply
  • I fully understand how the code works, including any changes generated by or with the assistance of AI

Local verification passed for query-core tests, its TypeScript matrix, lint, package build, formatting, and documentation links. The only remaining repository-wide failure was a Next.js example whose build-time PokeAPI request is unavailable in the restricted environment.

🚀 Release Impact

  • This change affects code that is released to users, and I have added a changeset
  • This is a documentation, CI, or development-only change, and no changeset is needed

@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

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.

@TkDodo
TkDodo requested a review from Ephem September 5, 2026 12:29
@nx-cloud

nx-cloud Bot commented Sep 6, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit a97345f

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

☁️ Nx Cloud last updated this comment at 2026-09-06 09:40:08 UTC

@pkg-pr-new

pkg-pr-new Bot commented Sep 6, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

npm i https://pkg.pr.new/@tanstack/lit-query@11395

@tanstack/preact-query

npm i https://pkg.pr.new/@tanstack/preact-query@11395

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@11395

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: a97345f

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.

1 participant