From 8e280992f0bf7f90cb656f054ab04a665739c1ae Mon Sep 17 00:00:00 2001 From: floriskn <48930050+floriskn@users.noreply.github.com> Date: Mon, 16 Jun 2025 11:52:48 +0200 Subject: [PATCH] fix: ensure undefined attributes are removed during hydration Attributes that are `undefined` on the client should be removed during hydration, even if their value hasn't changed compared to `prev_value`. --- .../svelte/src/internal/client/dom/elements/attributes.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/svelte/src/internal/client/dom/elements/attributes.js b/packages/svelte/src/internal/client/dom/elements/attributes.js index fcce0b444f..e61f9b5679 100644 --- a/packages/svelte/src/internal/client/dom/elements/attributes.js +++ b/packages/svelte/src/internal/client/dom/elements/attributes.js @@ -345,7 +345,11 @@ export function set_attributes(element, prev, next, css_hash, skip_warning = fal } var prev_value = current[key]; - if (value === prev_value) continue; + + // Skip if value is unchanged, unless it's `undefined` and the element still has the attribute + if (value === prev_value && !(value === undefined && element.hasAttribute(key))) { + continue; + } current[key] = value;