Open dm-de opened 4 days ago
setContext
should be called inside the component script and not inside an effect (actually i'm surprised it's not erroring our might be worth taking a look).
The warning you get is because you are passing some stateful value and it's not within a closure so if the array itself updates the child will not get updates (you will still get updates in case a member of the array is updated).
You can either silence the warning if you know you will never reassign the array or wrap it in a getter/closure.
thx... I misunderstood that warning. I thought, I need to use $effect.
State referenced in its own scope will never update. Did you mean to reference it inside a closure?
so here is an summary: 1) missing error for setContext inside $effect 2) missing information in docs about passing function with setContext: https://svelte.dev/docs/svelte/svelte#setContext 3) missing this nice tricks in example https://svelte.dev/docs/svelte/context
missing information in docs about passing function with setContext: https://svelte.dev/docs/svelte/svelte#setContext
You don't HAVE to use functions with setContext
you just need if you want to keep reactivity alive and that is true for every function boundary.
According to the documentation, we should use an "arbitrary context object". Of course I also used Array. I just didn't expect it to work this with a function.
Describe the bug
After setting an array, I use setContext inside $effect. This feels right - otherwise a warning come up. But my subcomponent do not get context. Array is undefined
Same thing with object
Reproduction
ARRAY
OBJECT
Logs
No response
System Info
Severity
blocking an upgrade