Svelte(Kit) reactivity without #key #1883
-
Can we have svelte stores for the m function so we can use $m to make the language reactive without having a need for wrapping the whole page in a #key block. This is extremely important for me because all the data that got changed inside components gets reloaded on a language change. It seems like you implemented this here, but i cannot find it anywhere how to use it, or is this still in development? Thanks a lot! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 17 replies
-
Doesn't work. Svelte stores are not tree-shakable. You have to wait for Svelte runes, which will solve Svelte's reactivity limitations. Maybe @LorisSigrist has another idea. |
Beta Was this translation helpful? Give feedback.
-
@LorisSigrist It would also be possible to create a language store that contains "en" | "de" and get's updated after Then use the translation functions together with the store in the markup like so: Remove the This will re-render the text whenever the language store changes value. Without re-rendering the whole page. I'm curios to what you think about this solution |
Beta Was this translation helpful? Give feedback.
There are a few things you could try.
You could store the state in an SvelteKit Snapshot and then reload the page when changing languages. That way the state would survive the language change.
You could also try to create an
$m
store like so, that updates whenever the language changes:This should work, but it has a drawback. Treeshaking no longer works, so all messages will always…