Skip to content

Alternative for Svelte 5 store initialization in load() #14612

Answered by brunnerh
WitnessMee asked this question in Q&A
Discussion options

You must be logged in to vote

You should not use global state as soon as your application has some server component (e.g. SSR) and separate users. The state will be shared between users on the server which can lead to data leaks.

So you generally should return data directly from load functions.

The additional onMount should be skippable; $effect callbacks run on mount, so usually a single $effect to update the local state would be enough. The if statement seems a bit redundant, the page also should only receive messages relevant to the conversation. (The ID from the URL can be accessed via $page.params and does not need to be passed by load.)

You should not need to manually synchronize local state variables unless you…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by WitnessMee
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants