Replies: 2 comments 3 replies
-
Yes! This is definitely planned and as you noted, by containing the logic within the loader, it can be preloaded 😁 |
Beta Was this translation helpful? Give feedback.
-
I can have a go at contributing if you'd like? Do you think the general idea would be something like: export function preloadData(route) {
const loaders = collectLoaders(route)
return executeLoaders(loaders, route)
} Where Enabling this would involve the following steps:
I'm assuming you'd want to explicitly pass the given route in for (3) rather than just setting the current context as that could have other unintended consequences? There are probably various other gotchas/considerations to consider, but does this sound roughly like the right idea? |
Beta Was this translation helpful? Give feedback.
-
Since all the data required for a route is nicely contained inside a route's loader, it'd be great to be able to use this to prefetch/preload data for a route. This is especially useful when you can infer that a user is likely to navigate to a new route, for example on hover.
This idea is essentially the same as SvelteKit's
preloadData
. They also havedata-sveltekit-preload-data
that is an additional option on their<RouterLink>
equivalent but this is just a bonus. The underlyingpreloadData
functionality is the interesting bit.One quick way to enable this would be to allow a
route
to be passed touseLoader
instead of internally retrieving the current route. This would allow you to importuseLoader
from wherever it's exported and just call it with the route you expect the user navigate to. For example, one might end up with:You could improve the ergonomics of this in various ways up to the equivalent what SvelteKit's versions provide afterwards at some point.
This all would likely only be useful for any loader implementation that has some kind of caching mechanism baked in, like
pinia-colada
orvue-query
, otherwise you'd just end up double fetching the data once you actually navigate to the route.Beta Was this translation helpful? Give feedback.
All reactions