Don't wait for server load
to run client load
and remove its data
input
#6570
mquandalle
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
What about this use case? // +page.server.js
export async function load() {
// database is only accessible on server
return { fromServer: await db.get() }
}
// +page.js
export async function load({ data, fetch }) {
const url = `http://externalapi.com/something/${data.fromServer}`
// trip between browser <-> external api instead of browser <-> server <-> external api
const res = await fetch(url);
return { fromClient: res.ok && await res.json() }
} |
Beta Was this translation helpful? Give feedback.
1 reply
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.
-
The documentation describes the
data
parameter of theload
function as being very rarely needed, but it doesn't show an actual use case where it could come in handy. This gives me 2 ideas:load
functions instead of passing a parameter?Sveltekit merges the data provided by different
load
functions from the layout hierarchy, so my intuition would be that load functions from+page.server.js
and+page.js
would also get merged:stackblitz
But instead we need to manually merge the data on the client using the
data
parameter:Which seems out of pace with the rest of the
load
API. I'm not convinced that the client overwritingdata
from the server is ever needed, but if that was the case I would expect to see something likeawait parent()
orawait serverLoad()
instead of the ambiguousdata
parameter.Related: #6459
load
function on the client could be run instantly without waiting on the serverThis would be useful in the rare cases where the load function is expensive to run.
I'm also thinking that this pattern could allow “optimistic loading” by first rendering the page with
+page.js
data, and then re-render it with the data from the server as described in #6298. This is a separate idea which probably need better design consideration, but I think there should be an intuitive way to do partial loading with the data already present on the client.Beta Was this translation helpful? Give feedback.
All reactions