Skip to content

The latest value, instead of the previous value, is provided in $effect teardown if the state is a $derived #16114

@OptimisticSean

Description

@OptimisticSean

Describe the bug

Not sure if this is a bug or intended. According to this breaking change, if the state caused an $effect to rerun, Svelte should provide the previous value of the state in the teardown function. This work for $state currently, but not for $derived, though it does work if $derived is reassigned.

Reproduction

https://svelte.dev/playground/untitled?version=5.33.18#H4sIAAAAAAAACnWPy2rEMAxFf8WIgcl0woSuCm4SmC_oqqumizyU1tRVjKVkOgT_e3HS92MldHSPZM9A9TOChlsSIxY7SKE3Fhn03QxydnEWAaTvyaNzB57QSmRNzfgXbwcSJGHQkHPrjZOyokosimJVqA1LLZhc7q4_6II79GbCLuELXkZUyQb7HltJkp0qSjVHVEk7EA8WD3Z4SLaPRjFrtU0Vr5ZU4lFGT-qb9ENrzvjbC7GEXUV59vlsyptRZCA1UGtN-1TM617e70N57DrFebYmyv-z8X9XobyZ0J-8kXj7q-VK1mrmkGfurV36FUAKgi8CWvyI4T4FqY09GepA97VlDK_x94v_xwEAAA==

Logs

System Info

Svelte playground (5.33.18)
Chrome 137.0.7151.56

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugp0stuff we should fix ASAP

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions