Skip to content

Strange combination of unused $state and $derived causes missing rerender #9738

@kuechlerm

Description

@kuechlerm

Describe the bug

I have a super strange bug in my project and I was able to reduce it down to the provided REPL.
If you click the buttons A and B multiple times, the content of the #if block does not get changed anymore.
If you remove one of the lines that I describe in comments, the bug is gone.
The most easy fix is - of course - not having any unused variables. But that was not easy to spot in a big refactoring and maybe this points to a underlying problem.

Update 1

This is not so edge-casy as I thought. I have the same issue even with no unused state variables in a more complex setup. Much harder to reproduce unfortunately. I will give it another try...

Update 2

The problem is definitely related to the filter function in the $derived prop.
This workaround works: REPL without $derived

Reproduction

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAE5VT0Y6bMBD8lS13UkAK0FbXFxIikf5C3y734MCScw9sZC_pXS3-vbYxyUWt1FZ58Swzu-PJ2kQt71BHxaOJBOsxKqJqGKJ1RG-DA_qMHaHFWo6qdpWtrhUfaHcQALwfpCIwQM9cnDRM0CrZwyrLv_lCNstXm4OwP8pzUNjLMzq-BiYae0A4jiew8CQFOlaHBKMYNTZQwr0mRhh_TGyLbX4ZbUHDz-5AXztev0Dlu-2BEXTINMEDEO9RO1VgXiUH2h5HIilAitrJSxMnUO7CNTJiRzt6Va0m2FXbfOb-j3LvlPt3yj-YMHe8vZGV88h5zIEqTyqw0xhq--DgQ5r-LUdI0-DX3CGrn5dBHbfRMA2csL9MMg5lQoaCyZ3CA5Pzdrpxr-mtQ9_altYQwjBLq1YKSjX_iQU8fBle3f9OvsGss3vUy4a3HJuoIDXitL6s3c3GXBfwu36_fHXHtIaZOk-dEw9rYvNLwq41jNj1w6MRsoBP0xr84fP05Hnk87CsBhU_YxO7PDP7IghVnCytFrxc89_W2Fpzzay_zQwV0qiE12TO3RKOS1rgq39JtRTWUHhNJQj8ES4bJ5vfw3uafgFrBsHYvwMAAA==

Logs

No response

System Info

REPL

Severity

annoyance

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions