-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
Describe the bug
Hi, I found an issue that might be expected behavior but it's odd as you can make it work by mutating unrelated state
When using the rune $state inside a class to expose a prop, myClass.prop
it behaves as expected, it also behaves correctly when nesting it inside a sub property that is itself another class myClass.childClass.prop
But when that childClass is optional, that is myClass.childClass?.prop
things get weird, primitives like string, boolean, numbers work fine, they are reactive all the way back to the ui, but when using an array method like push
it is not reactive.
The odd thing about all of this is that if you have two or more $states
s inside the class chain and modify any of them, the changes of the push
do get propagated.
I created this simple repro in the svelte playground, it uses two classes,
TestClass and OptionalChild, the OptionalChild get initiated after one second using set Interval (but this works by any delayed initialization)
Inside we modify the array every second but it does not update in the UI, if you uncomment any of the lines that modify other props it will suddenly also update the array state in the UI
Reproduction
Logs
System Info
using firefox/chrome in svelte playground
Severity
annoyance