Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-baboons-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: respect `svelte-ignore hydration_attribute_changed` on elements with spread attributes
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ export function SvelteElement(node, context) {
node,
element_id,
attributes_id,
b.binary('===', b.member(element_id, 'namespaceURI'), b.id('$.NAMESPACE_SVG')),
b.call(b.member(b.member(element_id, 'nodeName'), 'includes'), b.literal('-'))
b.id('$$preserve_attribute_case'),
b.id('$$is_custom_element')
);
}

Expand Down Expand Up @@ -158,7 +158,16 @@ export function SvelteElement(node, context) {
context.state.node,
get_tag,
node.metadata.svg || node.metadata.mathml ? b.true : b.false,
inner.length > 0 && b.arrow([element_id, b.id('$$anchor')], b.block(inner)),
inner.length > 0 &&
b.arrow(
[
element_id,
b.id('$$anchor'),
b.id('$$preserve_attribute_case'),
b.id('$$is_custom_element')
],
b.block(inner)
),
dynamic_namespace && b.thunk(build_attribute_value(dynamic_namespace, context).value),
location && b.array([b.literal(location.line), b.literal(location.column)])
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ export function build_set_attributes(
element_id,
is_dynamic ? attributes_id : b.literal(null),
b.object(values),
element.metadata.scoped &&
context.state.analysis.css.hash !== '' &&
b.literal(context.state.analysis.css.hash),
element.metadata.scoped && context.state.analysis.css.hash !== ''
? b.literal(context.state.analysis.css.hash)
: is_custom_element
? b.null
: false,
Copy link
Member

Choose a reason for hiding this comment

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

what's this change about? Why null in one case and false in the other?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just to generate a null instead of undefined for custom-element :

$.set_attributes(cust_elem, attributes_1, { ...rest }, undefined, true, true);
// =>
$.set_attributes(cust_elem, attributes_1, { ...rest }, null, true, true);

But maybe it's useless...

Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine to keep it as undefined — there's probably a bunch of places where we have these arguments that are omitted in favour of defaults if there are no subsequent non-falsy arguments, and if we always added this logic it would make the codebase more cluttered. With gzip the extra characters won't matter

preserve_attribute_case,
is_custom_element,
is_ignored(element, 'hydration_attribute_changed') && b.true
Expand Down
12 changes: 9 additions & 3 deletions packages/svelte/src/internal/client/dom/blocks/svelte-element.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @import { Effect, TemplateNode } from '#client' */
import { FILENAME, NAMESPACE_SVG } from '../../../../constants.js';
import { FILENAME, NAMESPACE_MATHML, NAMESPACE_SVG } from '../../../../constants.js';
import {
hydrate_next,
hydrate_node,
Expand Down Expand Up @@ -28,7 +28,7 @@ import { is_raw_text_element } from '../../../../utils.js';
* @param {Comment | Element} node
* @param {() => string} get_tag
* @param {boolean} is_svg
* @param {undefined | ((element: Element, anchor: Node | null) => void)} render_fn,
* @param {undefined | ((element: Element, anchor: Node | null, preserve_attribute_case: boolean, is_custom_element: boolean) => void)} render_fn,
* @param {undefined | (() => string)} get_namespace
* @param {undefined | [number, number]} location
* @returns {void}
Expand Down Expand Up @@ -137,11 +137,17 @@ export function element(node, get_tag, is_svg, render_fn, get_namespace, locatio
}
}

var is_custom_element = element.nodeName.includes('-');
var preserve_attribute_case =
is_custom_element ||
element.namespaceURI === NAMESPACE_SVG ||
element.namespaceURI === NAMESPACE_MATHML;

// `child_anchor` is undefined if this is a void element, but we still
// need to call `render_fn` in order to run actions etc. If the element
// contains children, it's a user error (which is warned on elsewhere)
// and the DOM will be silently discarded
render_fn(element, child_anchor);
render_fn(element, child_anchor, preserve_attribute_case, is_custom_element);
}

// we do this after calling `render_fn` so that child effects don't override `nodes.end`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ export function set_attributes(
// @ts-ignore
element[name] = value;
} else if (typeof value !== 'function') {
set_attribute(element, name, value);
set_attribute(element, name, value, skip_warning);
}
}
if (key === 'style' && '__styles' in element) {
Expand Down