Navigation fails when using nested Colada Loaders #2653
-
Version5.0.3 Reproduction linkhttps://github.com/penpenpng/colada-loader-bug-repro Steps to reproduceAnd click the What is expected?I am looking for one of the following:
What is actually happening?Navigation fails with the warning In my application, I need to call two APIs during page initialization. The second call depends on the result of the first one, so they must be executed sequentially. I also want these API calls to be cached individually by Pinia Colada. I defined the loaders as follows: // Dummy APIs
const getNext = async (x: number | string) => {
return new Promise<number>((resolve) => {
setTimeout(() => {
resolve(Number(x) + 1);
}, 100);
});
};
const NEXT_QUERY_KEY = (x: number | string) => ["next", x];
// Data Loaders
export const useNextLoader = defineColadaLoader({
key: (route) => NEXT_QUERY_KEY(route.params.value),
query: (route) => getNext(route.params.value),
});
export const useNextNextLoader = defineBasicLoader(async () => {
const next = await useNextLoader();
const useNextNextLoader = defineColadaLoader({
key: () => NEXT_QUERY_KEY(next),
query: () => getNext(next),
});
return useNextNextLoader();
});I assumed this was valid based on the Nested Loader constraints, and I believe Interestingly, wrapping the first loader with - const next = await useNextLoader();
+ const next = await withLoaderContext(useNextLoader()); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
Defining a loader inside of a loader is def not supported (it could work in some scenarios though) On a first look this looks like a loss of the context in pinia colada loader, I will investigate further. Why are you mixing colada and basic loaders though? The only use case would be async combination of both data |
Beta Was this translation helpful? Give feedback.
Fixed in fce5d1e, there was a bug with context restoration
You can do something like
the issue is that the key must be definable before and without async, ideally it should come from
to. I might want to introduce a different syntax that allows passing parameters but that would go against the point of data loaders: they should be callable just by knowing the navigation. However, in your case this still technically holds tru since the parameter comes from another loader. I w…