You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This may be an edge use-case, but I'm curious if anyone else has a +layout.server.js file for the sole purpose of passing event.locals to the page's export let data or $page store. It's a bit boilerplate all by itself.
Lets assume locals contains locals.hello and locals.world
I'm curious about the possibility of a +page.svelte and/or +layout.svelte option that takes care of this automagically, and adds the locals info to either data (if exported) or $page. Would look something like this:
/* +page.svelte */<script>
import {page} from '$app/stores'
export const locals = true
/* locals is either explicitly available */
console.log($page.data.locals.hello, $page.data.locals.world)
/* or spread into `data` */
console.log($page.data.hello, $page.data.world)
</script>
You'd wanna have a trigger, not just locals automatically getting passed through; because people sometimes store sensitive data in locals for use only on the server-side, and that data shouldn't be passed to the client. Hence, needing to do something like export const locals = true to get this behavior.
This feature wouldn't save any code if you're doing other things in +layout.server.js. At that point you already have the shell code in place. It'd be easy to just bring in locals and add it to the return statement with the rest of your data.
Cons
Goes against the concept of having only one way of doing something.
Hides the fact that something is happening on the server-side which you don't see, because it's not explicitly defined in +layout.server.js.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This may be an edge use-case, but I'm curious if anyone else has a
+layout.server.jsfile for the sole purpose of passingevent.localsto the page'sexport let dataor$pagestore. It's a bit boilerplate all by itself.Lets assume locals contains
locals.helloandlocals.worldI'm curious about the possibility of a
+page.svelteand/or+layout.svelteoption that takes care of this automagically, and adds thelocalsinfo to eitherdata(if exported) or$page. Would look something like this:You'd wanna have a trigger, not just
localsautomatically getting passed through; because people sometimes store sensitive data inlocalsfor use only on the server-side, and that data shouldn't be passed to the client. Hence, needing to do something likeexport const locals = trueto get this behavior.This feature wouldn't save any code if you're doing other things in
+layout.server.js. At that point you already have the shell code in place. It'd be easy to just bring in locals and add it to the return statement with the rest of your data.Cons
+layout.server.js.Beta Was this translation helpful? Give feedback.
All reactions