Replies: 2 comments 1 reply
-
|
In your first example export async function clientLoader({ serverLoader }: Route.ClientLoaderArgs) {
// Resolves data from single-fetch request because of `preload` flag.
// Does not initiate new request.
let serverData = serverLoader()
return {
rows: enrichWithClientData(serverData.rows)
}
}
clientLoader.preload = true // new flagHere This could let you start doing work before the server loader is requested, but at any moment await the result from the single fetch, kinda like this. // this doesn't block the client loader
let serverLoaderPromise = callServerLoader({ request, params });
let result = await callClientLoader({
request,
params,
context,
serverLoader: () => serverLoaderPromise
}); |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
Thanks to @dadamssg for a sample POC implementation here: #14635 If this moves forward we can re-open that or use it as a starting point 👍 |
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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
tl;dr
Background
Currently, having a
clientLoaderdefined in a route module automatically opts it out of single-fetch and requires a separate request because theclientLoadercould end up not calling theserverLoader(). This is perfect for use-cases like debouncing requests.However, often times
clientLoaders solely exist to enrich the server data with data only available on the client. Some examples include:In these cases, the
serverLoaderwill always be called and reducing network requests would be ideal. This is more impactful now that middleware has landed since it wouldn't be running again in a separate request.Proposal
A new
preloadflag to be optionally added toclientLoaders, similar to thehydrateflag. If this is set, the route loader will always participate in single-fetch. TheserverLoader()would return the data from the single-fetch request instead of initiating a new fetch to get the loader data.Alternatives
Currently, if you want the route to participate in single-fetch and enrich with client data you would need to do that in the route component.
Alternatively, this was discussed from the team previously:
Beta Was this translation helpful? Give feedback.
All reactions