Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kuechlerm opened this issue Dec 1, 2023 · 1 comment · Fixed by #9837
Closed

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

kuechlerm opened this issue Dec 1, 2023 · 1 comment · Fixed by #9837
Assignees

Comments

@kuechlerm
Copy link

kuechlerm commented Dec 1, 2023

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

@trueadm
Copy link
Contributor

trueadm commented Dec 4, 2023

This is likely because when you remove the $state, it becomes non-runes mode. In non-runes mode we don't use === equality on state and derived, but we do in runes mode. I'm going to take a hunch it has something to do with that, however, I can dig into it more tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants