From fe4b86d36b5b90eb25a821792a71474b8446b1f8 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 25 May 2025 12:06:18 -0400 Subject: [PATCH] WIP --- .../src/internal/client/dom/elements/attributes.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/svelte/src/internal/client/dom/elements/attributes.js b/packages/svelte/src/internal/client/dom/elements/attributes.js index 35afa5e7c4..80d390441d 100644 --- a/packages/svelte/src/internal/client/dom/elements/attributes.js +++ b/packages/svelte/src/internal/client/dom/elements/attributes.js @@ -1,3 +1,4 @@ +/** @import { Effect } from '#client' */ import { DEV } from 'esm-env'; import { hydrating, set_hydrating } from '../hydration.js'; import { get_descriptors, get_prototype_of } from '../../../shared/utils.js'; @@ -479,7 +480,7 @@ export function attribute_effect( /** @type {Record} */ var prev = {}; - /** @type {Record} */ + /** @type {Record} */ var effects = {}; block(() => { @@ -487,9 +488,16 @@ export function attribute_effect( set_attributes(element, prev, next, css_hash, skip_warning); + for (let symbol of Object.getOwnPropertySymbols(effects)) { + if (!next[symbol]) destroy_effect(effects[symbol]); + } + for (let symbol of Object.getOwnPropertySymbols(next)) { - if (symbol.description === ATTACHMENT_KEY && next[symbol] !== prev[symbol]) { - effects[symbol] = branch(() => attach(element, () => next[symbol])); + var n = next[symbol]; + + if (symbol.description === ATTACHMENT_KEY && n !== prev[symbol]) { + if (effects[symbol]) destroy_effect(effects[symbol]); + effects[symbol] = branch(() => attach(element, () => n)); } }