svelte-html
Simon Holthausen 9 months ago
parent c30cf7121b
commit c7232220ad

@ -19,7 +19,7 @@ export function svelte_html(get_attributes) {
/** @type {Record<string, any>} Does _not_ contain event listeners, those are handled separately */ /** @type {Record<string, any>} Does _not_ contain event listeners, those are handled separately */
let attributes; let attributes;
const set_html_attributes = () => { render_effect(() => {
attributes = get_attributes(); attributes = get_attributes();
for (const name in attributes) { for (const name in attributes) {
@ -30,17 +30,7 @@ export function svelte_html(get_attributes) {
let value = attributes[name]; let value = attributes[name];
current.push({ owner: self, value }); current.push({ owner: self, value });
// Defer hydration on initial render during hydration: If there are attribute duplicates, the last value const set = () => {
// 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);
}
});
return;
}
if (name === 'class') { if (name === 'class') {
// Avoid unrelated attribute changes from triggering class changes // Avoid unrelated attribute changes from triggering class changes
if (old !== value) { if (old !== value) {
@ -49,10 +39,21 @@ export function svelte_html(get_attributes) {
} else { } else {
set_attribute(node, name, value); set_attribute(node, name, value);
} }
}
}; };
render_effect(set_html_attributes); // 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) {
set();
}
});
} else {
set();
}
}
});
teardown(() => { teardown(() => {
for (const name in attributes) { for (const name in attributes) {

Loading…
Cancel
Save