Skip to content

Commit

Permalink
fix: stringify attribute values before comparison (#9475)
Browse files Browse the repository at this point in the history
* fix: stringify attribute values before comparison

* simplify

---------

Co-authored-by: Rich Harris <[email protected]>
  • Loading branch information
Rich-Harris and Rich-Harris authored Nov 15, 2023
1 parent 2ebedb0 commit e3e1fef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/curly-lizards-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: coerce attribute value to string before comparison
5 changes: 4 additions & 1 deletion packages/svelte/src/internal/client/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -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);
Expand Down

1 comment on commit e3e1fef

@vercel
Copy link

@vercel vercel bot commented on e3e1fef Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

svelte-5-preview – ./sites/svelte-5-preview

svelte-5-preview-svelte.vercel.app
svelte-5-preview.vercel.app
svelte-octane.vercel.app
svelte-5-preview-git-main-svelte.vercel.app

Please sign in to comment.