fix: ensure element size bindings don't unsubscribe multiple times (#12091)

The `update` function could cause a read, which would end up being tracked in the effect, and said effect would then run multiple times when it should only run once

fixes #11934
fixes #12028
pull/12082/head
Simon H 7 months ago committed by GitHub
parent d04f69ac05
commit 2ca2979a46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: ensure element size bindings don't unsubscribe multiple times from the resize observer

@ -1,4 +1,5 @@
import { effect, teardown } from '../../../reactivity/effects.js';
import { untrack } from '../../../runtime.js';
/**
* Resize observer singleton.
@ -100,7 +101,8 @@ export function bind_element_size(element, type, update) {
var unsub = resize_observer_border_box.observe(element, () => update(element[type]));
effect(() => {
update(element[type]);
// The update could contain reads which should be ignored
untrack(() => update(element[type]));
return unsub;
});
}

Loading…
Cancel
Save