-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: clarifying session/locals key difference #1457
docs: clarifying session/locals key difference #1457
Conversation
For newbies, wrapping your head around the data flow of SvelteKit takes a minute. Calling out specifically that locals don't have to be serializable like session does can clarify some of this (speaking from experience!).
I hadn't merged this because I wanted some other opinions on it. The more I think about it, the more I wonder if this is the right change. There's lots of stuff that runs just on the server and I'm not sure we'd want to put this disclaimer on all of them as it might become noisy. If there's a reason this call in particular is confusing I wonder if we can address the underlying issue instead. You said " E.g. if we changed "This function runs on every request" to "This function runs on the server on every request" would that help? |
Hey @benmccann! I agree that we definitely wouldn't want to noise it up by adding this disclaimer to all of the code that runs server-side. I think that it's worth it in this special case, though. The underlying problem is that all of the nomenclature around the request/endpoint setup "sounds" like HTTP. You make This may not be the way to do it... but there should be some disclaimer or section here that shows how the |
This isn't a special case though. And |
I'm not sure I follow this:
How is Addendum on why I assumed fetch might not be making an actual HTTP request on the server side: It seemed silly to make a HTTP request from the server to the server because it seems like it'd be slower than finding a way to "directly" call the endpoint on the server side when it's not going to a remote URL ( Little note: It's super hard to convey tone, but believe me -- I know you know the backend way better than I do, and I of course defer to you and the rest of the Svelte team's judgment. My opinion is just one of user experience. |
A The name Thanks for taking the time to put together this PR. I'm going to go ahead and close it though because it seems like the confusion is at a more basic level and we should find a way to address that rather than this specific point |
Thanks for taking the time to review and converse! I definitely agree that a change to the naming would do a better job of alleviating the confusion than adding to the docs. |
For newbies, wrapping your head around the data flow of SvelteKit takes a minute. Calling out specifically that locals don't have to be serializable like session does can clarify some of this (speaking from experience!).
Before submitting the PR, please make sure you do the following
Tests
pnpm test
and lint the project withpnpm lint
Changesets
pnpx changeset
and following the promptsJust proposing a one-line change to the documentation on
request.locals
. When I dove into SvelteKit for the first time,handle
(thengetContext
) felt like it was making a HTTP request when it passed its response on to the endpoints. This gave me the impression thatlocals
(thencontext
) had to be serializable likesession
does. When I realized it didn't, it significantly simplified my auth/persistent session implementation. Calling this out clarifies this issue, especially for other newbies.