Skip to content

chore: small tweaks on set_attributes() #15413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
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