feat(vue-query): add usePrefetchQuery and usePrefetchInfiniteQuery#10372
feat(vue-query): add usePrefetchQuery and usePrefetchInfiniteQuery#10372thalassophilia wants to merge 3 commits intoTanStack:mainfrom
Conversation
📝 WalkthroughWalkthroughAdds two Vue prefetch composables— Changes
Sequence Diagram(s)sequenceDiagram
participant Dev as Developer
participant Vue as Vue (effect/watchEffect)
participant Composable as Prefetch Composable
participant QC as QueryClient
Dev->>Composable: invoke(options: maybe refs or getter)
Composable->>Vue: create watchEffect to resolve options
Vue->>Composable: resolved options (deep-unref/cloned)
Composable->>QC: getQueryState(resolved.queryKey)
QC-->>Composable: state (exists / undefined)
alt state undefined
Composable->>QC: prefetchQuery / prefetchInfiniteQuery(clonedOptions)
QC-->>Composable: prefetch result
else state exists
Composable-->>Dev: no-op (skip prefetch)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
docs/config.json (1)
1271-1305:⚠️ Potential issue | 🟠 MajorRe-add
Prefer Query Optionsto ESLint navigation.The ESLint rule is active in
packages/eslint-plugin-query/src/index.tsandpackages/eslint-plugin-query/src/rules.ts, documented atdocs/eslint/prefer-query-options.mdand listed indocs/eslint/eslint-plugin-query.md, but missing fromdocs/config.json. This leaves the documentation page orphaned and undiscoverable in the navigation.Proposed fix
{ "label": "Mutation Property Order", "to": "eslint/mutation-property-order" + }, + { + "label": "Prefer Query Options", + "to": "eslint/prefer-query-options" }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/config.json` around lines 1271 - 1305, Add the missing "Prefer Query Options" nav entry to docs/config.json so the documentation page is discoverable: locate the ESLint section children array (where other rules like "ESLint Plugin Query", "Exhaustive Deps", and "Stable Query Client" are listed) and insert an object with "label": "Prefer Query Options" and "to": "eslint/prefer-query-options"; this corresponds to the existing rule implementation in packages/eslint-plugin-query/src/index.ts and packages/eslint-plugin-query/src/rules.ts and the docs file docs/eslint/prefer-query-options.md.
🧹 Nitpick comments (1)
packages/vue-query/src/usePrefetchQuery.ts (1)
29-31: Consider extractingisGetterinto a shared internal helper.This helper is duplicated in
packages/vue-query/src/usePrefetchInfiniteQuery.ts; centralizing it would reduce drift.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/vue-query/src/usePrefetchQuery.ts` around lines 29 - 31, The isGetter helper is duplicated (function isGetter and its MaybeRefOrGetter usage) — extract it into a single internal helper module (e.g., an internal utils file) that exports isGetter<T>(value: MaybeRefOrGetter<T>): value is () => T and the needed types, then replace the local implementations in usePrefetchQuery (function isGetter) and usePrefetchInfiniteQuery with imports from that shared helper and remove the duplicate definitions so both files consume the same utility.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@docs/config.json`:
- Around line 1271-1305: Add the missing "Prefer Query Options" nav entry to
docs/config.json so the documentation page is discoverable: locate the ESLint
section children array (where other rules like "ESLint Plugin Query",
"Exhaustive Deps", and "Stable Query Client" are listed) and insert an object
with "label": "Prefer Query Options" and "to": "eslint/prefer-query-options";
this corresponds to the existing rule implementation in
packages/eslint-plugin-query/src/index.ts and
packages/eslint-plugin-query/src/rules.ts and the docs file
docs/eslint/prefer-query-options.md.
---
Nitpick comments:
In `@packages/vue-query/src/usePrefetchQuery.ts`:
- Around line 29-31: The isGetter helper is duplicated (function isGetter and
its MaybeRefOrGetter usage) — extract it into a single internal helper module
(e.g., an internal utils file) that exports isGetter<T>(value:
MaybeRefOrGetter<T>): value is () => T and the needed types, then replace the
local implementations in usePrefetchQuery (function isGetter) and
usePrefetchInfiniteQuery with imports from that shared helper and remove the
duplicate definitions so both files consume the same utility.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 869bf223-c4fc-42b4-8411-9df0a52c28a0
📒 Files selected for processing (11)
.changeset/puny-poems-tell.mddocs/config.jsondocs/framework/vue/reference/usePrefetchInfiniteQuery.mddocs/framework/vue/reference/usePrefetchQuery.mdpackages/vue-query/src/__tests__/usePrefetchInfiniteQuery.test-d.tspackages/vue-query/src/__tests__/usePrefetchInfiniteQuery.test.tspackages/vue-query/src/__tests__/usePrefetchQuery.test-d.tspackages/vue-query/src/__tests__/usePrefetchQuery.test.tspackages/vue-query/src/index.tspackages/vue-query/src/usePrefetchInfiniteQuery.tspackages/vue-query/src/usePrefetchQuery.ts
cfc42ae to
9057679
Compare
- Add usePrefetchQuery and usePrefetchInfiniteQuery to vue-query. - Includes runtime and type tests, plus a changeset
9057679 to
a72cdb5
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/vue-query/src/usePrefetchQuery.ts (1)
29-31: Consider extractingisGetterhelper to utils.This helper is duplicated in
usePrefetchInfiniteQuery.ts. Extracting it toutils.tswould reduce duplication.♻️ Suggested refactor
In
packages/vue-query/src/utils.ts:+export function isGetter<T>(value: MaybeRefOrGetter<T>): value is () => T { + return typeof value === 'function' +}Then import and use in both composables.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/vue-query/src/usePrefetchQuery.ts` around lines 29 - 31, Extract the duplicated isGetter helper into a shared utils module and import it from both composables: create an exported isGetter<T>(value: MaybeRefOrGetter<T>): value is () => T function in packages/vue-query/src/utils.ts, remove the local isGetter definitions in usePrefetchQuery (function isGetter) and usePrefetchInfiniteQuery, and update both files to import { isGetter } from './utils' so they share the single implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/vue-query/src/usePrefetchQuery.ts`:
- Around line 29-31: Extract the duplicated isGetter helper into a shared utils
module and import it from both composables: create an exported
isGetter<T>(value: MaybeRefOrGetter<T>): value is () => T function in
packages/vue-query/src/utils.ts, remove the local isGetter definitions in
usePrefetchQuery (function isGetter) and usePrefetchInfiniteQuery, and update
both files to import { isGetter } from './utils' so they share the single
implementation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 6fa81406-de50-46da-afb2-d52566b4410d
📒 Files selected for processing (11)
.changeset/puny-poems-tell.mddocs/config.jsondocs/framework/vue/reference/usePrefetchInfiniteQuery.mddocs/framework/vue/reference/usePrefetchQuery.mdpackages/vue-query/src/__tests__/usePrefetchInfiniteQuery.test-d.tspackages/vue-query/src/__tests__/usePrefetchInfiniteQuery.test.tspackages/vue-query/src/__tests__/usePrefetchQuery.test-d.tspackages/vue-query/src/__tests__/usePrefetchQuery.test.tspackages/vue-query/src/index.tspackages/vue-query/src/usePrefetchInfiniteQuery.tspackages/vue-query/src/usePrefetchQuery.ts
✅ Files skipped from review due to trivial changes (5)
- docs/framework/vue/reference/usePrefetchQuery.md
- docs/framework/vue/reference/usePrefetchInfiniteQuery.md
- .changeset/puny-poems-tell.md
- docs/config.json
- packages/vue-query/src/tests/usePrefetchInfiniteQuery.test-d.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- packages/vue-query/src/index.ts
- packages/vue-query/src/tests/usePrefetchQuery.test-d.ts
- packages/vue-query/src/tests/usePrefetchInfiniteQuery.test.ts
- packages/vue-query/src/tests/usePrefetchQuery.test.ts
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
docs/config.json (1)
1283-1317:⚠️ Potential issue | 🟠 MajorRe-add
prefer-query-optionsto ESLint navigation.The rule is still implemented and exported, but it is no longer listed in docs navigation. This de-lists a valid rule from the ESLint docs menu.
Suggested patch
{ "label": "Mutation Property Order", "to": "eslint/mutation-property-order" + }, + { + "label": "Prefer Query Options", + "to": "eslint/prefer-query-options" }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/config.json` around lines 1283 - 1317, The ESLint navigation block under the "ESLint" children array is missing the entry for the existing rule; add an object for the prefer-query-options rule to that children list (e.g., label "Prefer Query Options" and to "eslint/prefer-query-options") so the rule exported by the codebase is listed in the docs navigation; update the children array near the entries like "ESLint Plugin Query" / "Exhaustive Deps" / "Stable Query Client" / "No Rest Destructuring" to include this new item.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@docs/config.json`:
- Around line 1283-1317: The ESLint navigation block under the "ESLint" children
array is missing the entry for the existing rule; add an object for the
prefer-query-options rule to that children list (e.g., label "Prefer Query
Options" and to "eslint/prefer-query-options") so the rule exported by the
codebase is listed in the docs navigation; update the children array near the
entries like "ESLint Plugin Query" / "Exhaustive Deps" / "Stable Query Client" /
"No Rest Destructuring" to include this new item.
🎯 Changes
Add
usePrefetchQueryandusePrefetchInfiniteQueryto@tanstack/vue-query.This PR:
usePrefetchQueryandusePrefetchInfiniteQueryto the Vue adapter✅ Checklist
pnpm run test:pr.🚀 Release Impact
Validated with:
npx nx run @tanstack/vue-query:test:libnpx nx run @tanstack/vue-query:test:eslintSummary by CodeRabbit
New Features
Documentation
Tests
Chores