How do I diagnose strange data-loader behaviour? #611
-
Hi, I'm unable to work out why I'm getting various weird behaviours with both basic loaders and colada loaders while adding to an existing project. I tried to create a minimal reproduction, but it works fine, so something is different but I can't work out what. Hopefully someone can help point me in the right direction?! For instance, here is my loader: import { getProjects } from '@/api/projects.api'
import { parsePageQuery, parsePageSizeQuery } from '@/utils/parsing'
export const useProjects = defineColadaLoader('/projects', {
key: (to) => ['projects', { page: parsePageQuery(to.query.page), pageSize: parsePageSizeQuery(to.query.pageSize) }],
query: async (to) => {
const page = parsePageQuery(to.query.page)
const pageSize = parsePageSizeQuery(to.query.pageSize)
const projects = await getProjects({ page, pageSize })
console.info(`Returning project count: ${projects?.items?.length}`)
return projects
},
staleTime: 5000,
lazy: false,
}) I get const { data: projects, isLoading, error, reload } = useProjects()
watch (projects, data => console.info(`DataLoader: data: ${data?.items?.length}`))
watch (isLoading, loading => console.info(`DataLoader: isLoading: ${loading}`)) And this is what I see:
Before
I saw this mentioned in another discussion (561) by @posva, but I can't work out what I'm looking for. I can't find any dataloader hooks in either the working project or the failing one so I assume I'm looking in the wrong place:
Note that this code works perfectly, as expected, when I create a new project from scratch, hence I need to dig deep to find out why I'm seeing this (and other) behaviour. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
From the code sample, it looks like your API returns |
Beta Was this translation helpful? Give feedback.
Ah then it means you are not exporting the data loader from the page component