kit
kit copied to clipboard
Offer a way to avoid the waterfall because of nested layouts, `await parent()` to retrieve `locals`
Describe the problem
Let's say I have a few layouts that fetch data using session credentials.
// hooks.server.ts
export const handle = ({event, resolve}) => {
if (hasACertainCookie) {
event.locals.session = getSessionFromCookie()
}
return resolve(event)
}
// Root +layout.server.ts
export const load = ({locals}) => locals; // Expose all locals to layouts and pages
// Many +layout.ts and +page.ts look like this
export const load = ({parent}) => {
const {session} = await parent();
return { thing: fetch(..., session) }
}
This will unfortunately create a waterfall, despite the only needed data are the one from local.session
Describe the proposed solution
Svelte-Kit < 1 had a session feature which allowed constant-time access to a bag of top props, and it can be used as inspiration
Alternatives considered
No response
Importance
would make my life easier
Additional Information
No response