Skip to content

Commit 2ca2979

Browse files
authored
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
1 parent d04f69a commit 2ca2979

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

.changeset/gorgeous-hats-wonder.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: ensure element size bindings don't unsubscribe multiple times from the resize observer

packages/svelte/src/internal/client/dom/elements/bindings/size.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { effect, teardown } from '../../../reactivity/effects.js';
2+
import { untrack } from '../../../runtime.js';
23

34
/**
45
* Resize observer singleton.
@@ -100,7 +101,8 @@ export function bind_element_size(element, type, update) {
100101
var unsub = resize_observer_border_box.observe(element, () => update(element[type]));
101102

102103
effect(() => {
103-
update(element[type]);
104+
// The update could contain reads which should be ignored
105+
untrack(() => update(element[type]));
104106
return unsub;
105107
});
106108
}

0 commit comments

Comments
 (0)