Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm committed Dec 18, 2024
1 parent c30cf71 commit c723222
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions packages/svelte/src/internal/client/dom/blocks/svelte-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function svelte_html(get_attributes) {
/** @type {Record<string, any>} Does _not_ contain event listeners, those are handled separately */
let attributes;

const set_html_attributes = () => {
render_effect(() => {
attributes = get_attributes();

for (const name in attributes) {
Expand All @@ -30,29 +30,30 @@ export function svelte_html(get_attributes) {
let value = attributes[name];
current.push({ owner: self, value });

const set = () => {
if (name === 'class') {
// Avoid unrelated attribute changes from triggering class changes
if (old !== value) {
set_class(node, current_setters[name].map((e) => e.value).join(' '));
}
} else {
set_attribute(node, name, value);
}
};

// Defer hydration on initial render during hydration: If there are attribute duplicates, the last value
// wins, so we wait until all values have been set to see if we're actually the last one that sets the value.
if (hydrating) {
effect(() => {
if (current[current.length - 1].owner === self) {
untrack(set_html_attributes);
set();
}
});
return;
}

if (name === 'class') {
// Avoid unrelated attribute changes from triggering class changes
if (old !== value) {
set_class(node, current_setters[name].map((e) => e.value).join(' '));
}
} else {
set_attribute(node, name, value);
set();
}
}
};

render_effect(set_html_attributes);
});

teardown(() => {
for (const name in attributes) {
Expand Down

0 comments on commit c723222

Please sign in to comment.