-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Effect is not called when using state in svelte non-component file #15328
Comments
There is some issue here with effects not being triggered correctly, but that code is also buggy. All conditions in effects have to be some kind of state, otherwise the effect will easily end up with zero dependencies and never run again. Only dependencies that are hit during effect execution will trigger the effect again later. Your One of the things that apparently does not work here is an |
This is because the component you're creating the class in is from a legacy component. Effects only invalidate themselves in runes mode. |
That does not seem right, especially for a root effect defined outside the component. |
The root effect is being created from the component – and component context is shared this way. We can't change this otherwise we'd break the ability to do |
In my real example, the things are even worse since I dont have a svelte component. I'm having just And then, eventually, some time in future, a Svelte component might be (or might be not!) mounted into the DOM and then it will play with the store ($state from So I'm not sure whats the best way to achieve this. As for me, as I've stated above - something either buggy or I'm doing it wrong (although I was inspired by https://www.matsimon.dev/blog/svelte-in-depth-effect-root but again, I dont have Svelte mounted yet) |
Describe the bug
.svelte.js
file, definestate([])
propertyconstructor
, defineeffect.root -> effect
which will console.log when the state updatesSome of investigations:
See the REPL. If I will store this store globally, and then somewhen call
window.globalStoreReference.all = []
- now effects will start working - wat.I have a feeling that I'm not doing something right although this is pretty much logical way to do it after reading the docs and some articles about such usages.
Reproduction
https://svelte.dev/playground/7fb9745958a64a96b09b3c32b8b2594a?version=5.20.1
Open console, see that there are some info about value of the state.
Click button -> state value updates but the effect never called since there are no new console.logs calls.
Logs
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: