Comments (5)
From my understanding, I'd say that you're indeed misusing stores, and this is how Svelte 5 fine-grained reactivity works. You're not changing the value of $state
itself, but merely mutating the $state
object, which doesn't cause an update from the store's point of view.
The reason that it works in Svelte 4, is not because of store updates, but because of the compiler invalidating the whole state
prop when you mutate state.checked
.
function input_change_handler() {
state.checked = this.checked;
$$invalidate(0, state);
}
This makes $: console.log({ Checkbox: state })
works as expected, but comes with a cost of invalidating everything that depends on state
, even though the actual value doesn't change (i.e. $: console.log(state.completely_unrelated_property)
will also re-run when state.checked
is changed, see REPL)
In Svelte 5, the compiler no longer "guesses" what changed, instead moving that to run-time using signals. And since there are no signals on state.checked
, nothing gets updated. FYI, converting your example to use $state
works as expected.
from svelte.
If the Checkbox
component is in legacy mode, it works as expected.
It will cause the state
setter to be called in the binding.
$.bind_checked(
input,
() => state().checked,
($$value) => state((state().checked = $$value, state()))
);
from svelte.
Well, stores are still a supported part of Svelte 5 and they just do not have fine-grained reactivity.
So a case could be made that this should be backward compatible.
A problem probably is that the Checkbox
component does not know that the property gets its value from a store. On the App
side, access to the store is wrapped in a get/set pair:
Checkbox(node, {
get state() {
return $state();
},
set state($$value) {
$.store_set(state, $$value);
}
});
The setter is currently not invoked. Maybe some metadata could be passed along to make the Checkbox
aware that a store is being passed in and that the setter needs to be called, e.g. by proxying the prop. Might be a bit complicated, though.
from svelte.
This looks to be working as expected for runes mode. Svelte 4 doesn't have runes mode, so you're not comparing apples to apples.
I wonder if you remove the usage of runes, does this issue go away? Then it will force the components into legacy mode which eagerly overreads because of the lack of fine grain reactivity. Legacy mode is also more aligned to how Svelte 4 works, so if there's a difference then that's likely a bug we need to fix.
from svelte.
I'd say this works as expected in runes mode, though the behavior is probably a bit surprising at first. I'm wondering if there's a way to warn in this case (in dev mode).
from svelte.
Related Issues (20)
- duplicate component issue is caused by using the fade transition. HOT 2
- Svelte 5 exports in rune mode to expose variables for programmatic use (for instance updates) HOT 3
- Svelte 5: Incorrect IfBlock Start Position in Modern Mode Parsing HOT 4
- Svelte 5: Maximum update depth exceeded. (effect_update_depth_exceeded) HOT 14
- hydrate and mount error out in browser, saying 'hydrate(...)' is not available on the server HOT 4
- Add setter to let variables accessors HOT 3
- Svelte 5: cannot bind to a `<svelte:component/>` element HOT 2
- Svelte 5: Flickering CSS transitions/animations starting in `next-144` HOT 1
- Svelte 5: Imported component applied global style HOT 2
- Svelte 5: Invalid namespace of elements within SVG HOT 5
- `render` function from `svelte/server` not properly typed
- preventDefault not working HOT 1
- Svelte 5: Can not reassign $derived variable HOT 8
- false positive a11y warning for label with control inside component HOT 6
- Uneasy bouncing in `transition:slide` HOT 12
- bug: getting $Ci not a constructor for imports of svg , png in static builds HOT 2
- SSR code regression between 152 and 153
- Svelte5: Snippet block name conflict with component name causes error HOT 1
- [Svelte5] Svelte mount duplicate issue HOT 7
- Svelte 5: events created with the "on" function will bubble separately from one another
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svelte.