Skip to content

Commit e3e1fef

Browse files
authored
fix: stringify attribute values before comparison (#9475)
* fix: stringify attribute values before comparison * simplify --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>
1 parent 2ebedb0 commit e3e1fef

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Diff for: .changeset/curly-lizards-dream.md

+5
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

Diff for: packages/svelte/src/internal/client/render.js

+4-1
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 : 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)