From e3e1fef238c2439786dc7885495dd1c8c173b6c6 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 15 Nov 2023 15:19:43 -0500 Subject: [PATCH] fix: stringify attribute values before comparison (#9475) * fix: stringify attribute values before comparison * simplify --------- Co-authored-by: Rich Harris --- .changeset/curly-lizards-dream.md | 5 +++++ packages/svelte/src/internal/client/render.js | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .changeset/curly-lizards-dream.md 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);