sveltejs/svelte

`$derived($state.eager())` reactivity loss

Opened this issue · 1 comments

Describe the bug

Since 5.43.4 if you include $state.eager() in a $derived or $derived.by the reactivity can stop working.

Reproduction

REPL

<script>
    let open = $state(false);

    const derivedEagerOpen = $derived($state.eager(open));

    $inspect('derivedEagerOpen', derivedEagerOpen);
</script>

<button onclick={() => open = !open}>Toggle</button>

<p>open: {open}</p>
<p>derivedEagerOpen: {derivedEagerOpen}</p>

Please keep in mind this is just a silly minimal reproduction of the underlying cause of some complex bits-ui popover issues I've been having. Please believe me there is a good reason for using $state.eager like this. (closing a combobox immediately after selecting to be consistent with native select element behaviour). (somewhere bits-ui uses boxWith from svelte-toolbelt which uses a $derived.by on the bound $state.eager(open).

Logs

System Info

Svelte playground

Severity

blocking an upgrade

I don't know about the $state.eager issue but for the popover, again move await to the bottom of script