Skip to content

Conversation

@itamarzwi
Copy link
Contributor

@itamarzwi itamarzwi commented Oct 23, 2025

🎯 Changes

Change the value passed to queryKey in the vue examples to be reactive and trigger a refetch when the prop 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).

Fixes #9782

Summary by CodeRabbit

  • Documentation
    • Updated Vue Query examples to demonstrate improved query key handling patterns for optimal caching behavior across Vue 2.6, 2.7, and 3.x applications.

@changeset-bot
Copy link

changeset-bot bot commented Oct 23, 2025

⚠️ No Changeset found

Latest commit: a4673af

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 23, 2025

Walkthrough

Changed queryKey configuration in five Vue example Post.vue files, replacing static props.postId values with function wrappers () => props.postId. This alters query key formation to use delayed function evaluation instead of direct property references, affecting how Vue Query tracks reactivity and manages caching behavior.

Changes

Cohort / File(s) Summary
Vue Query Examples β€” queryKey Function Wrapping
examples/vue/2.6-basic/src/Post.vue,
examples/vue/2.7-basic/src/Post.vue,
examples/vue/basic/src/Post.vue,
examples/vue/dependent-queries/src/Post.vue,
examples/vue/persister/src/Post.vue
Changed queryKey second element from static props.postId to function accessor () => props.postId, altering key computation and Vue reactivity tracking. queryFn and all other query configuration remain unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

The changes follow a consistent, homogeneous pattern across five files with identical logic modifications. Review complexity is straightforwardβ€”each change is a single configuration adjustment. However, reviewers should verify that the function-wrapped query key properly integrates with Vue Query's reactivity system and does not introduce unintended re-fetch behavior.

Possibly related issues

Poem

🐰 A rabbit's blessing for your key,
No longer static, now it's free!
Functions wrapped in deference deep,
Vue's reactivity runs so steepβ€”
The cache shall dance, the queries gleam! ✨

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
βœ… Passed checks (2 passed)
Check name Status Explanation
Title Check βœ… Passed The pull request title "docs(examples): update queryKey to be reactive in vue files" directly and accurately summarizes the main change in the changeset. The title clearly identifies what is being changed (queryKey), where the changes apply (vue files), and the nature of the modification (to be reactive). This is consistent with the actual changes across all modified files, which wrap the postId value in a function to make the queryKey reactive and trigger refetches when props change. The title is concise, follows conventional commit format, and avoids vague or misleading language.
Description Check βœ… Passed The pull request description includes all required template sections and is substantially complete. The 🎯 Changes section clearly describes what was modified and the motivation behind it (making queryKey reactive to trigger refetches when props change). The βœ… Checklist section shows both items are completed with checkmarks, confirming the contributing guide was followed and code was tested locally. The πŸš€ Release Impact section is properly filled out, with the appropriate checkbox marked indicating this is a docs/CI/dev-only change with no release impact. The description is specific, not vague, and provides sufficient context for reviewers.
✨ Finishing touches
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
examples/vue/basic/src/Post.vue (1)

23-25: Same suggestion: use toRef/computed for the reactive part of the key.

Your change works; using a ref is a bit clearer and improves inference.

-      queryKey: ['post', () => props.postId],
+      queryKey: ['post', toRef(props, 'postId')],

Add import:

- import { defineComponent } from 'vue'
+ import { defineComponent, toRef } from 'vue'
examples/vue/dependent-queries/src/Post.vue (1)

34-36: Prefer computed/toRef for the key to match the rest of the file.

Works as-is. Since you already use computed, consider:

-      queryKey: ['post', () => props.postId],
+      queryKey: ['post', computed(() => props.postId)],

Alternatively:

-      queryKey: ['post', () => props.postId],
+      queryKey: ['post', toRef(props, 'postId')],

(If you pick toRef, add toRef to the Vue import.)

examples/vue/persister/src/Post.vue (1)

25-27: Tweak tuple for clearer typing with persister.

This works. To avoid a function in the tuple type and keep inference tidy, prefer a ref/computed:

Option A (keep as const):

-      queryKey: ['post', () => props.postId] as const,
+      queryKey: ['post', toRef(props, 'postId')] as const,

Option B (no as const, simplest):

-      queryKey: ['post', () => props.postId] as const,
+      queryKey: ['post', toRef(props, 'postId')],

Add import:

- import { defineComponent } from 'vue'
+ import { defineComponent, toRef } from 'vue'
examples/vue/2.6-basic/src/Post.vue (1)

23-25: Vue 2.6: use toRef for the reactive key source.

Change is fine. Using a ref avoids a function inside the key prior to unwrapping.

-      queryKey: ['post', () => props.postId],
+      queryKey: ['post', toRef(props, 'postId')],

Add import:

- import { defineComponent, toRaw } from '@vue/composition-api'
+ import { defineComponent, toRaw, toRef } from '@vue/composition-api'
πŸ“œ Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 6c272bd and a4673af.

πŸ“’ Files selected for processing (5)
  • examples/vue/2.6-basic/src/Post.vue (1 hunks)
  • examples/vue/2.7-basic/src/Post.vue (1 hunks)
  • examples/vue/basic/src/Post.vue (1 hunks)
  • examples/vue/dependent-queries/src/Post.vue (1 hunks)
  • examples/vue/persister/src/Post.vue (1 hunks)
πŸ”‡ Additional comments (1)
examples/vue/2.7-basic/src/Post.vue (1)

23-25: Current implementation follows Vue Query v5 recommendations; refactor is optional.

The inline getter in queryKey is officially supported and recommended by Vue Query v5 for trivial property access like props.postId. Using toRef is also valid but unnecessary hereβ€”reserve toRef/computed for cases requiring memoization or expensive derived state. No changes required.

@nx-cloud
Copy link

nx-cloud bot commented Oct 24, 2025

View your CI Pipeline Execution β†— for commit a4673af

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

☁️ Nx Cloud last updated this comment at 2025-10-24 12:57:04 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 24, 2025

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: a4673af

@DamianOsipiuk DamianOsipiuk merged commit 9371479 into TanStack:main Oct 24, 2025
7 checks passed
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.

Vue example has a reactivity problem

2 participants