Skip to content

docs({react,preact,solid,vue}-query/useQuery): add 'initialDataUpdatedAt' to the seeding example - #11579

Open
sukvvon wants to merge 1 commit into
mainfrom
docs/seeding-example-initial-data-updated-at
Open

sukvvon wants to merge 1 commit into
mainfrom
docs/seeding-example-initial-data-updated-at

Conversation

@sukvvon

@sukvvon sukvvon commented Sep 22, 2026

Copy link
Copy Markdown
Member

🎯 Changes

The "Seeding a detail query from an already-cached list" @example in each of react-query, preact-query, solid-query, and vue-query's useQuery.ts used initialData to look up a detail item from an already-cached list query, but didn't set initialDataUpdatedAt.

Without it, the seeded data's dataUpdatedAt defaults to Date.now() (packages/query-core/src/query.ts), so if a staleTime is later set on the query, staleness is measured from "now" instead of from when the source list was actually fetched — which can make stale seeded data look fresh for longer than intended.

This is the pattern the framework's own guide already documents and recommends (docs/framework/react/guides/initial-query-data.md, "Initial Data from the cache with initialDataUpdatedAt" — "Instead of using an artificial staleTime ... it's suggested that you pass the source query's dataUpdatedAt to initialDataUpdatedAt"), with the exact same getQueryState(...)?.dataUpdatedAt call. This PR brings the useQuery reference example in line with that guide.

Added initialDataUpdatedAt: () => queryClient.getQueryState(['posts'])?.dataUpdatedAt to the example in all four adapters, and a sentence explaining why.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.

🚀 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

  • Documentation
    • Expanded query examples across supported frameworks to show how seeded detail queries can preserve the cached list’s fetch timestamp.
    • Clarified that staleTime is measured from the original list fetch when using initialDataUpdatedAt.
    • Updated source-code reference links in API documentation.

@coderabbitai

coderabbitai Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: TanStack/query/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: c2cdf502-c756-4578-b8a8-dd6cf45664f9

📥 Commits

Reviewing files that changed from the base of the PR and between 129955c and 34a1eec.

📒 Files selected for processing (9)
  • docs/framework/preact/reference/functions/useQuery.md
  • docs/framework/react/reference/functions/useQuery.md
  • docs/framework/solid/reference/functions/useQuery.md
  • docs/framework/solid/reference/variables/createQuery.md
  • docs/framework/vue/reference/functions/useQuery.md
  • packages/preact-query/src/useQuery.ts
  • packages/react-query/src/useQuery.ts
  • packages/solid-query/src/useQuery.ts
  • packages/vue-query/src/useQuery.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The PR updates useQuery and createQuery documentation. Seeded detail-query examples now pass the cached list's dataUpdatedAt through initialDataUpdatedAt. Several source links use updated line numbers.

Changes

Initial data timestamp documentation

Layer / File(s) Summary
Package JSDoc examples
packages/*-query/src/useQuery.ts
The cached-list seeding examples explain initialDataUpdatedAt and derive it from the cached posts query state.
Framework reference examples and links
docs/framework/preact/reference/functions/useQuery.md, docs/framework/react/reference/functions/useQuery.md, docs/framework/solid/reference/functions/useQuery.md, docs/framework/solid/reference/variables/createQuery.md, docs/framework/vue/reference/functions/useQuery.md
The reference examples include initialDataUpdatedAt, and the source links use updated line numbers.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Other

Merge Risk: ⚪ Minimal · up to 34a1e

This update documents more accurate seeded-query freshness behavior without changing published runtime code, so no merge-blocking production risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the framework adapters, the useQuery example, and the addition of initialDataUpdatedAt. It accurately summarizes the main change.
Description check ✅ Passed The description explains the motivation, implementation, affected adapters, testing status, and release impact. It includes all required template sections and checklist items.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 4…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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.

@nx-cloud

nx-cloud Bot commented Sep 22, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 34a1eec

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

☁️ Nx Cloud last updated this comment at 2026-09-22 08:34:11 UTC

@sukvvon sukvvon self-assigned this Sep 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

No changeset entries found. Merging this PR will not cause a version bump for any packages.

@pkg-pr-new

pkg-pr-new Bot commented Sep 22, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 34a1eec

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
react full 11.87 KB (0%)
react minimal 8.85 KB (0%)

This branch has not been deployed

No deployments
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