sveltejs / kit

web development, streamlined
https://kit.svelte.dev
MIT License
17.8k stars 1.78k forks source link

`preloadData` should be able to cache multiple routes at a time #12122

Open rileylyman opened 1 month ago

rileylyman commented 1 month ago

Describe the problem

Reading the docs and using preloadData, I had always assumed I could call it multiple times and that it would cache each route. I've actually been using it this way for months and never noticed somehow. Due to lack of documentation of this limitation, I was very confused for a while and it wasn't until I dug into the code that I confirmed my suspicions that the load cache can only store one route at a time.

Describe the proposed solution

I think preloadData should be able to cache multiple routes at a time. Perhaps the maximum number of routes to be cached could be set in the config or something. This would be a huge help for my app where many pages make lots of fetches that could be effectively hidden this way.

I understand that it isn't really desirable to cache a bunch of routes when you are hovering over links with data-sveltekit-preload-data="hover", but I think that when the dev calls preloadData manually, there is no reason to clear the other cached routes in that case. If the dev did want to clear the cache, maybe that could be an optional argument to preloadData or a separate function entirely, but I think that's overcomplicating it.

I think the simplest thing would be just to allow N number of routes to be cached at the same time, tweakable by the user via config.

Alternatives considered

No response

Importance

would make my life easier

Additional Information

No response