fix: stringify attribute values before comparison (#9475)

* fix: stringify attribute values before comparison

* simplify

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/9431/head
Rich Harris 1 year ago committed by GitHub
parent 2ebedb04a1
commit e3e1fef238
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: coerce attribute value to string before comparison

@ -2658,9 +2658,12 @@ export function attr_effect(dom, attribute, value) {
* @param {string | null} value * @param {string | null} value
*/ */
export function attr(dom, attribute, value) { export function attr(dom, attribute, value) {
value = value == null ? null : value + '';
if (DEV) { if (DEV) {
check_src_in_dev_hydration(dom, attribute, value); check_src_in_dev_hydration(dom, attribute, value);
} }
if ( if (
current_hydration_fragment === null || current_hydration_fragment === null ||
(dom.getAttribute(attribute) !== value && (dom.getAttribute(attribute) !== value &&
@ -2671,7 +2674,7 @@ export function attr(dom, attribute, value) {
attribute !== 'src' && attribute !== 'src' &&
attribute !== 'srcset') attribute !== 'srcset')
) { ) {
if (value == null) { if (value === null) {
dom.removeAttribute(attribute); dom.removeAttribute(attribute);
} else { } else {
dom.setAttribute(attribute, value); dom.setAttribute(attribute, value);

Loading…
Cancel
Save