Occasional loss of reactivity with defineQuery and useRoute #173
-
Hi there, I'm encountering a bit of a strange issue when using While using To isolate the issue, I've set up a brand new installation of Nuxt (repo available here) and I'm getting the same results there as well. Here's a short screen recording of the reproduction. The "test data" should change along with the slug. Recording.2025-01-29.142020.mp4The query: // ~/queries/page.ts
export const usePage = defineQuery(() => {
const route = useRoute();
return useQuery({
key: () => ['pages', route.params.slug as string],
query: () => delay(route.params.slug as string)
})
})
// delay to imitate fetch
function delay(str: string) {
return new Promise(resolve => setTimeout(() => {
resolve(str);
}, 200));
} The page component: <template>
<!-- ~/pages/[slug].vue -->
<div>
<pre>slug: {{ route.params.slug }}</pre>
<pre>test data: {{ data }}</pre>
</div>
</template>
<script setup lang="ts">
import { usePage } from '~/queries/page';
const { data } = usePage();
const route = useRoute();
</script> |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Hello! This seems to be working as expected: you are seeing first the delay and then the cache data being immediately reused with no delay. Queries are waiting on load but not by navigation. You can |
Beta Was this translation helpful? Give feedback.
Thanks! Now I can reproduce it! It seems to be related to the tracking mechanism in defined queries. The one initially visited isn't properly tracked and creates bugs