pinia-colada: Nuxt unplugin-vue-router. With frequent requests, there is no data in the state. Abort signal not working when lazy true
When quickly navigating to the next pagination page, when 2 or more data requests are executed in parallel, the data disappears from state.value.data and placeholderData . However, it is present in data.value.
Because of this I have to use data.value.
I expect that data should not be lost.
- Operating System: Linux
- Node Version: v22.12.0
- Nuxt Version: 3.15.4
- CLI Version: 3.22.2
- Nitro Version: 2.10.4
- Package Manager: pnpm@9.15.4
- Builder: -
- User Config: ssr, future, experimental, modules, compatibilityDate, devtools, css, app, components, hooks
- Runtime Modules: @nuxt/eslint@1.1.0, @nuxt/icon@1.10.3, @pinia/nuxt@0.10.1, @pinia/colada-nuxt@0.0.5
- Build Modules: -
Lazt = true (Abort signal not working)
import { defineColadaLoader } from "unplugin-vue-router/data-loaders/pinia-colada";
export const useCarListData = defineColadaLoader("moulages-cars-accepted", {
key(route) {
const inputs = route.query.input ?? "";
const input = (Array.isArray(inputs) ? inputs[0] : inputs) ?? "";
return ["cars", input];
},
query(route, ctx) {
return $fetch(`/api/cars`, {
signal: ctx.signal,
});
},
placeholderData(data) {
if (!data) console.error("Empty: placeholderData");
return data;
},
lazy: (to, from) => !!(from && to.name === from.name),
});
<script setup lang="ts">
import { useCarListData } from "./model";
definePageMeta({
layout: "moulages",
loaders: [useCarListData],
});
const { data, state } = useCarListData();
watchSyncEffect(() => {
if (!data.value) console.error("Empty: data", data.value);
if (!state.value.data) console.error("Empty: state.data", state.value.data, state.value.status);
});
const inputQuery = useInputQuery();
const page = computed(() => inputQuery.input?.page ?? 1);
</script>
<template>
<PageMain>
<PageHeader>
<template #title>
<PageHeaderTitle> Page {{ page }} </PageHeaderTitle>
</template>
</PageHeader>
<PagePagination>
<CarCardList>
<CarCard v-for="car in data?.data ?? []" :key="car.id" :car="car">
<template #actions>
<ReturnCar variant="neutral" :id="car.id" />
<RejectCar :id="car.id" />
</template>
</CarCard>
</CarCardList>
<template #footer>
<Pagination :pagination="data?.meta" />
</template>
</PagePagination>
</PageMain>
</template>
https://github.com/user-attachments/assets/7fedf9c1-f528-45fb-9275-40f8409a624b
Lazy = false + abort signal
import { defineColadaLoader } from "unplugin-vue-router/data-loaders/pinia-colada";
export const useCarListData = defineColadaLoader("moulages-cars-accepted", {
key(route) {
const inputs = route.query.input ?? "";
const input = (Array.isArray(inputs) ? inputs[0] : inputs) ?? "";
return ["cars", input];
},
query(route, ctx) {
return $fetch(`/api/cars`, {
signal: ctx.signal,
});
},
placeholderData(data) {
if (!data) console.error("Empty: placeholderData");
return data;
},
lazy: false
// lazy: (to, from) => !!(from && to.name === from.name),
});
https://github.com/user-attachments/assets/fff7f7bf-7c65-4e4e-bd70-6771557d38d5
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 18 (7 by maintainers)
Commits related to this issue
- feat: pass previous placeholderData if present Close #197 — committed to 87xie/pinia-colada by posva 2 years ago
Instead of calling cancelQueries, you can create a plugin that matches your specific needs:
Check the source code of the plugins/delay (or others) to extend this even further.
You can implement all the things you want already but I wouldn’t recommend to use this for the reasons mentioned above. Note that the goal is not to be like tanstack query. The goal is to ease migration from it. Changes in default behavior that are beneficial like this one are simply bonus.
To summarize the reasons so far:
signalis different which makes me think I should expose both signals posva/unplugin-vue-router#605