renderLoader - a loader than runs on the render target
#10599
jakearchibald
started this conversation in
Proposals
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
A couple of times I've ran into issues where:
An example is cases where one of 100s of components is needed depending on state such as URL or cookies. Doing the work async within the component tree is not acceptable, because that would require a suspense boundary, and therefore wouldn't server render.
Duplicating code between the
loaderandclientLoaderdoesn't work, because the tree is hydrated before theclientLoaderdata is available. Plus you need to use hacks to prevent the unserialisable data being serialised in theloader(eg mark it as notenumerable.I feel like I need a loader that runs where the rendering will be performed.
Here's how I understand loading happens now, assuming a fresh tab load:
loaderruns on the serverloaderdata is deserialised on the clientloaderdataclientLoaderwithhydrate = trueruns on the client.clientLoaderdata.And here's what I'm looking for:
loaderruns on the serverrenderLoaderruns on the serverrenderLoaderdata. But only theloaderdata is serialised.loaderdata is deserialised on the clientrenderLoaderruns on the clientrenderLoaderdataclientLoaderwithhydrate = trueruns on the client.clientLoaderdata.In cases where it's an SPA navigation:
loaderdataloaderruns on the server, and the data is returnedloaderdata is deserialised on the clientrenderLoaderruns on the clientclientLoaderwithhydrate = trueruns on the client.clientLoaderdata.I think it would be rare to use
renderLoaderandclientLoadertogether, but I wanted to be clear about the ordering.An example of a render loader:
For the API above, I'm following the patterns of the
clientLoader. Hopefully this demonstrates the use-case, asMainComponentneed to be there in the server render, and having all possibilities of./components/${loaderData.componentToLoad}/index.tsxin the route bundle would be unacceptable.serverLoaderinClientLoaderFunctionArgswould need to be renamed, as it would be returning the result of therenderLoaderif one is present, not the "server loader". Maybe a name could be found that works for both therenderLoaderandclientLoader.loaderDatamight be good enough?Beta Was this translation helpful? Give feedback.
All reactions