diff --git a/.changeset/curly-lizards-dream.md b/.changeset/curly-lizards-dream.md new file mode 100644 index 0000000000..1f7d32f484 --- /dev/null +++ b/.changeset/curly-lizards-dream.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: coerce attribute value to string before comparison diff --git a/packages/svelte/src/internal/client/render.js b/packages/svelte/src/internal/client/render.js index 68f9ffdb31..9f05591753 100644 --- a/packages/svelte/src/internal/client/render.js +++ b/packages/svelte/src/internal/client/render.js @@ -2658,9 +2658,12 @@ export function attr_effect(dom, attribute, value) { * @param {string | null} value */ export function attr(dom, attribute, value) { + value = value == null ? null : value + ''; + if (DEV) { check_src_in_dev_hydration(dom, attribute, value); } + if ( current_hydration_fragment === null || (dom.getAttribute(attribute) !== value && @@ -2671,7 +2674,7 @@ export function attr(dom, attribute, value) { attribute !== 'src' && attribute !== 'srcset') ) { - if (value == null) { + if (value === null) { dom.removeAttribute(attribute); } else { dom.setAttribute(attribute, value);