From 2ca2979a46cf7410deb341c28fc063fadb48dbc1 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Wed, 19 Jun 2024 20:17:22 +0200 Subject: [PATCH] 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 --- .changeset/gorgeous-hats-wonder.md | 5 +++++ .../svelte/src/internal/client/dom/elements/bindings/size.js | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changeset/gorgeous-hats-wonder.md diff --git a/.changeset/gorgeous-hats-wonder.md b/.changeset/gorgeous-hats-wonder.md new file mode 100644 index 0000000000..e1ce7bdaed --- /dev/null +++ b/.changeset/gorgeous-hats-wonder.md @@ -0,0 +1,5 @@ +--- +"svelte": patch +--- + +fix: ensure element size bindings don't unsubscribe multiple times from the resize observer diff --git a/packages/svelte/src/internal/client/dom/elements/bindings/size.js b/packages/svelte/src/internal/client/dom/elements/bindings/size.js index e0ad045d80..c817787497 100644 --- a/packages/svelte/src/internal/client/dom/elements/bindings/size.js +++ b/packages/svelte/src/internal/client/dom/elements/bindings/size.js @@ -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; }); }