Closed marbemac closed 10 months ago
Thank you. This is interesting. Sorry it took me so long to get back here. I am not sure if you saw the work Ryan Turnquist did on https://github.com/solidjs/solid-router/compare/main...next
He was the original co-author of this library and started on a preload approach but I was never sure if this is how we wanted to do it. The problem with re-running the data functions is it does nothing unless we cache the results.. we had decided we'd leave that to the library, but we never had a blessed solution so the feature didn't really work well.
We talked about keeping the results of the data function around and then passing them into the actual render as available as that wouldn't waste work, but they would be live queries at that point so managing their lifecycle might be hard. I'm gathering you are doing the latter. Can you describe a bit more about the behavior? Am I correct in my understanding? LIke if something is preloaded at what point to do we throw it away?
No worries! Ah no I hadn't seen Ryan's work.
Yeah... imho data caching prob should not be a concern of solid-router. However, this opt-in preload behavior gives end users the option to combine solid-router with other libs that handle data caching - for example this functionality pairs very nicely with solid-query.
Happy to say this will be resolved by #312
This PR adds
preload
(similar toremix
) andpreloadDelay
(similar totanstack-router
) options to theRouter
andLink
components.I'm slowly making my way over from the world of React, so the particular implementation I chose might not be ideal - happy to adjust as ya'll see fit. I tried to minimize the amount of change, but it felt a little awkward to get access to the relevant route data and asset preload functions in the right spots given how things are currently organized (I ended up storing
branches
down to the route context - I'm not sure if there are any potential side effects to doing this).Usage
If the target route has a data function AND/OR if it has a lazy loaded component, the data func and lazy assets will be prefetched.