Open
Description
Describe the bug
Dynamic components in Svelte 5 + Sveltekit do not update correctly after SSR. The state updates, but the rendered component doesn't reflect this change:
store.ts:
import { browser } from "$app/environment";
const someStore = () => {
let someCondition = $state(false)
if(browser){
someCondition = true
}
return {
get someCondition () {
return someCondition
}
}
}
export const store = someStore()
+page.svelte:
<script lang="ts">
import A from './A.svelte'
import B from './B.svelte'
import {store} from './store'
$inspect(store.someCondition)
const SelectedComponent = $derived(store.someCondition ? A : B)
</script>
<!-- should display A, but displays B -->
<SelectedComponent />
{store.someCondition}
$inspect() and {store.someCondition} both show true. SelectedComponent should render A, however it renders B.
its kinda like #12333 just for components.
with this workaround in the store.ts it correctly updates to A:
if (browser) {
setTimeout(() => {
someCondition = true;
}, 0);
}
Reproduction
in the repl its working correctly. however locally in a fresh sveltekit + svelte 5 project its not.
Logs
No response
System Info
System:
OS: Linux 6.5 Ubuntu 23.10 23.10 (Mantic Minotaur)
CPU: (24) x64 AMD Ryzen 9 3900X 12-Core Processor
Memory: 21.84 GB / 31.26 GB
Container: Yes
Shell: 5.9 - /usr/bin/zsh
Binaries:
Node: 20.11.1 - /usr/local/lib/nodejs/node-v20.11.1-linux-x64/bin/node
Yarn: 1.22.22 - /usr/local/lib/nodejs/node-v20.11.1-linux-x64/bin/yarn
npm: 10.2.4 - /usr/local/lib/nodejs/node-v20.11.1-linux-x64/bin/npm
bun: 1.1.30 - ~/.bun/bin/bun
Browsers:
Brave Browser: 129.1.70.123
Chrome: 129.0.6668.89
npmPackages:
svelte: ^5.0.0-next.1 => 5.0.0-next.262
Severity
annoyance