Skip to content

Commit c5d5a14

Browse files
committed
fix: stringify attribute values before comparison
1 parent d749685 commit c5d5a14

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

.changeset/curly-lizards-dream.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: coerce attribute value to string before comparison

packages/svelte/src/internal/client/render.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2658,9 +2658,12 @@ export function attr_effect(dom, attribute, value) {
26582658
* @param {string | null} value
26592659
*/
26602660
export function attr(dom, attribute, value) {
2661+
value = value == null ? null : stringify(value);
2662+
26612663
if (DEV) {
26622664
check_src_in_dev_hydration(dom, attribute, value);
26632665
}
2666+
26642667
if (
26652668
current_hydration_fragment === null ||
26662669
(dom.getAttribute(attribute) !== value &&
@@ -2671,7 +2674,7 @@ export function attr(dom, attribute, value) {
26712674
attribute !== 'src' &&
26722675
attribute !== 'srcset')
26732676
) {
2674-
if (value == null) {
2677+
if (value === null) {
26752678
dom.removeAttribute(attribute);
26762679
} else {
26772680
dom.setAttribute(attribute, value);

0 commit comments

Comments
 (0)