You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've previously brought this up in the svelte-5-alpha chat and thought that it'd be worth raising an issue for a discussion.
Currently, as shown in this REPL, declaring global reactive state in context="module" behaves more similarly to local state that's declared in a component, rather than global state that's declared in an external module.
I find this difference in behavior to be a bit confusing as I would expect the global state declared in both, the external module and in context="module", to behave the same.
One could argue it should be the other way around - the imported state should also throw an error if accessed like this. The reason is that shared state should be imported at the usage locations and modified there, rather than being passed around as props and then modified, which creates indirection and makes reasoning about the code more confusing.
One could argue it should be the other way around - the imported state should also throw an error if accessed like this.
I would be okay with this too, maybe even prefer it! My main concern is consistency in the context of a module. As long as shared state behaves the same when passing it as a prop, I'd be happy with either approach.
I will say though, having both throw an error when passed around as a prop (without being bound too) would be my preference as it jives better with my mental model.
I think it's easier to understand the rule: this prop must be bound if the child component mutates it
instead of: this prop must be bound if the child component mutates it, _unless_ it's shared state from an external module, but not shared state declared in context='module'.
Describe the bug
I've previously brought this up in the svelte-5-alpha chat and thought that it'd be worth raising an issue for a discussion.
Currently, as shown in this REPL, declaring global reactive state in
context="module"
behaves more similarly to local state that's declared in a component, rather than global state that's declared in an external module.I find this difference in behavior to be a bit confusing as I would expect the global state declared in both, the external module and in
context="module"
, to behave the same.Reproduction
REPL
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: