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
Binding to a store through a component does an unnecessary set to the store with it's current value
Reproduction
<!-- Main.svelte -->
<scriptlang="ts">
import { typeWritable } from"svelte/store";importCheckboxComponentfrom"./CheckboxComponent.svelte";typeMyWritable<T> =Writable<T> & { value:T; subs:Set<(newValue:T) =>any>; };function log(...args:any[]) {console.log(newError().stack?.replace(/.*Error\n/, ""))console.log(...args); }function createWritable<T>(initial:T):MyWritable<T> {let ret:MyWritable<T> = { value: initial, subs: newSet(), set(newV) {// compiler/compile/render_dom/invalidate.js:108 invalidate svelte variable ?// compiler/compile/render_dom/invalidate.js:125 invalidate svelte store ?// compiler/compile/render_dom/wrappers/InlineComponent/index.js:372 where invalidate for both is created ?log({ set: newV });ret.value=newV;ret.subs.forEach(subscriber=>subscriber(ret.value)); }, update(callback) {let newV =callback(ret.value);log({ update: newV });ret.set(newV); }, subscribe(subscriber) {subscriber(ret.value);log({ subscribe: subscriber });ret.subs.add(subscriber);return () => {log({ unsub: subscriber });ret.subs.delete(subscriber); }; }, };returnret; }const writable =createWritable(false);
</script>
<!-- binding to elements directly does not trigger a set on the store -->
<inputtype="checkbox"bind:checked={$writable} />
<CheckboxComponentbind:checked={$writable} />
<!-- CheckboxComponent.svelte -->
<scriptlang="ts">
exportlet checked:boolean;
</script>
<inputtype="checkbox"bind:checked>
<!-- could also be just a <div>{checked}</div> and it would be the same result -->
Logs
at log (http://localhost:5173/src/pages/components/BindSet.svelte?t=1705537115510:131:14)
at Object.subscribe (http://localhost:5173/src/pages/components/BindSet.svelte?t=1705537115510:151:4)
at subscribe (http://localhost:5173/node_modules/.vite/deps/chunk-2KUOQYVC.js?v=90f11c1d:87:23)
at component_subscribe (http://localhost:5173/node_modules/.vite/deps/chunk-2KUOQYVC.js?v=90f11c1d:96:32)
at instance (http://localhost:5173/src/pages/components/BindSet.svelte?t=1705537115510:170:2)
at init (http://localhost:5173/node_modules/.vite/deps/chunk-2KUOQYVC.js?v=90f11c1d:2166:23)
at new BindSet (http://localhost:5173/src/pages/components/BindSet.svelte?t=1705537115510:201:3)
at createProxiedComponent (http://localhost:5173/node_modules/svelte-hmr/runtime/svelte-hooks.js?v=90f11c1d:341:9)
at new ProxyComponent (http://localhost:5173/node_modules/svelte-hmr/runtime/proxy.js?v=90f11c1d:242:7)
at new Proxy<BindSet> (http://localhost:5173/node_modules/svelte-hmr/runtime/proxy.js?v=90f11c1d:349:11)
BindSet.svelte:12
{subscribe: ƒ}
> subscribe: value =>$$invalidate(0, $writable = value)[[Prototype]]: Object
BindSet.svelte:11
at log (http://localhost:5173/src/pages/components/BindSet.svelte?t=1705537115510:131:14)
at Object.set (http://localhost:5173/src/pages/components/BindSet.svelte?t=1705537115510:140:4)
at Array.checkboxcomponent_checked_binding (http://localhost:5173/src/pages/components/BindSet.svelte?t=1705537115510:184:12)
at checkboxcomponent_checked_binding (http://localhost:5173/src/pages/components/BindSet.svelte?t=1705537115510:44:47)
at bind (http://localhost:5173/node_modules/.vite/deps/chunk-2KUOQYVC.js?v=90f11c1d:2099:5)
at http://localhost:5173/src/pages/components/BindSet.svelte?t=1705537115510:58:31
at flush (http://localhost:5173/node_modules/.vite/deps/chunk-2KUOQYVC.js?v=90f11c1d:1304:30)
BindSet.svelte:12
{set: false}
BindSet.svelte:11
Describe the bug
Binding to a store through a component does an unnecessary set to the store with it's current value
Reproduction
Logs
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: