-
-
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
Writable page store #6181
Comments
@fcrozatier That was my problem, too. I have a popup login and before API change I could update session without to reload/refresh the page and was good to go. Now I POST fetch my login endpoint (+server.js, export const POST = async ({ locals, params, request })) and await my api response. When the response is ok, I do In Login.svelte (import { invalidate } from "$app/navigation";) then on the positive Response from the endpoint I do That updates the page store behind and updates the Maybe this might be a way for your solution :) |
I've tried to implement your solution but when I update the locals in the endpoint, even if I invalidate afterwards, it does not reflect in the main layout locals. Here is a repo of what I tried |
@fcrozatier I am using plain javascript and and the static adapter. Common data is stored in a writeable storage, user data is stored inside an https-only cookie. Let me see.... routes:
+page.svelte
+layout.svelte +layout.server.js
+server.js
|
I found this issue too. Most importantly, the invalidation of the session request forced the client to ask the server again about the session but didn't update the $page at all. As I remember, @Rich-Harris advised to use reset invalidation for load function in |
Basically, without such a feature, I can't update the user parameters like name, avatar and etc. |
@stalkerg My problem here is, the login form is not a separate page that can reload/refresh but a popup login. So the current page is not triggering any page.(server.)js files. With the invalidation from the endpoint response it is working. Maybe my setup with static adapter is doing some magic that worked before SvelteKit API change and now works again. Yet :D |
@CodexAnima ok, just |
@CodexAnima in your case I think it's the cookie that makes it work. Remove the cookie and then I guess you get no chocolate.
That would be convoluted to have to write a cookie each time I want to communicate data to the root layout, there must be another way ? |
@fcrozatier well, the cookie keeps the logged in user persistent even when reloading the page. logging out removes the cookie and user is back to default |
@CodexAnima Ok I see your point, using cookies is a perfectly valid design and maybe it's the right way to achieve communication to the root layout. |
@fcrozatier then again, keep in mind I need this setup for a full static adapter build for persisting user logged status. Since then I keep my cookies and chocolate ;) |
Ok so to summarize the discussion:
In the end this design may be superior to a writable page store were data won't persist, won't be available in the server and thus won't be in sync :) |
Maybe there will be a similar implementation in a future SvelteKit version before version 1.0 🙏 |
Yep, seems to be where the project is heading #5875 |
Describe the problem
The session store was removed in #5946 and the suggested pattern instead is to use the page store to access the data fetched in the main layout #5883
But the session store was writable, where the page store is only readable
So let say I do not fecth all the user data in my main layout, but then need to update it or add data to it from a +page. How could I do this?
Describe the proposed solution
I don't see all the implications of this solution but a writable page store would allow this pattern.
Alternatives considered
No response
Importance
would make my life easier
Additional Information
No response
The text was updated successfully, but these errors were encountered: