Replies: 1 comment
-
This would be great. I've got a proof of concept up here #11319 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Disclaimer:
I know this was a thing already previously requested (see #9188), however I would like to make an actual solution proposal which should not impact the current behavior of loaders executing in parallel.
Current situation
So far I know we know of a few workarounds to the issue of child routes requiring data from a parent route:
1. Use an external store (eg. react-query) to run fetches.
This has the added benefit of allowing some more detailed cache control (currently the way I am solving this issue).
2. Perform all data loading only in leaf routes (and use helper functions for data from parents).
This is quite error prone imho. It's way to easy for a developer to forget calling a parent loader which might perform some necessary setup work etc.
Proposed solution
The problem with loaders mentioned for example in #9188 was this:
However, just being asynchronous does not mean one loader cannot depend on another one.
The proposed solution would be for the router to store the promise of each route loader in the routing tree and make them available for child routes by some helper function (eg.
getLoaderPromise
) in the context.A code using this function could look like this:
The implementation also wouldn't be too difficult, as the internal router just has to store and provide the promises for each loader by their id in the current route pipeline.
Similar proposals: #9564
(I found this only after writing this one, but I find this here to be a lot easier on the implementation side)
Beta Was this translation helpful? Give feedback.
All reactions