Skip to content

Commit db44d66

Browse files
committed
determine element traits inside set_attributes
1 parent 346de0e commit db44d66

File tree

6 files changed

+13
-50
lines changed

6 files changed

+13
-50
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,7 @@ export function RegularElement(node, context) {
221221
if (has_spread) {
222222
const attributes_id = b.id(context.state.scope.generate('attributes'));
223223

224-
build_set_attributes(
225-
attributes,
226-
class_directives,
227-
context,
228-
node,
229-
node_id,
230-
attributes_id,
231-
(node.metadata.svg || node.metadata.mathml || is_custom_element_node(node)) && b.true,
232-
is_custom_element_node(node) && b.true
233-
);
224+
build_set_attributes(attributes, class_directives, context, node, node_id, attributes_id);
234225

235226
// If value binding exists, that one takes care of calling $.init_select
236227
if (node.name === 'select' && !bindings.has('value')) {

packages/svelte/src/compiler/phases/3-transform/client/visitors/SvelteElement.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ export function SvelteElement(node, context) {
113113
inner_context,
114114
node,
115115
element_id,
116-
attributes_id,
117-
b.id('$$preserve_attribute_case'),
118-
b.id('$$is_custom_element')
116+
attributes_id
119117
);
120118
}
121119

@@ -158,16 +156,7 @@ export function SvelteElement(node, context) {
158156
context.state.node,
159157
get_tag,
160158
node.metadata.svg || node.metadata.mathml ? b.true : b.false,
161-
inner.length > 0 &&
162-
b.arrow(
163-
[
164-
element_id,
165-
b.id('$$anchor'),
166-
b.id('$$preserve_attribute_case'),
167-
b.id('$$is_custom_element')
168-
],
169-
b.block(inner)
170-
),
159+
inner.length > 0 && b.arrow([element_id, b.id('$$anchor')], b.block(inner)),
171160
dynamic_namespace && b.thunk(build_attribute_value(dynamic_namespace, context).value),
172161
location && b.array([b.literal(location.line), b.literal(location.column)])
173162
)

packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/element.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,14 @@ import { build_template_chunk, get_expression_id } from './utils.js';
1717
* @param {AST.RegularElement | AST.SvelteElement} element
1818
* @param {Identifier} element_id
1919
* @param {Identifier} attributes_id
20-
* @param {false | Expression} preserve_attribute_case
21-
* @param {false | Expression} is_custom_element
2220
*/
2321
export function build_set_attributes(
2422
attributes,
2523
class_directives,
2624
context,
2725
element,
2826
element_id,
29-
attributes_id,
30-
preserve_attribute_case,
31-
is_custom_element
27+
attributes_id
3228
) {
3329
let is_dynamic = false;
3430

@@ -91,8 +87,6 @@ export function build_set_attributes(
9187
element.metadata.scoped &&
9288
context.state.analysis.css.hash !== '' &&
9389
b.literal(context.state.analysis.css.hash),
94-
preserve_attribute_case,
95-
is_custom_element,
9690
is_ignored(element, 'hydration_attribute_changed') && b.true
9791
);
9892

packages/svelte/src/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const UNINITIALIZED = Symbol();
3333
export const FILENAME = Symbol('filename');
3434
export const HMR = Symbol('hmr');
3535

36+
export const NAMESPACE_HTML = 'http://www.w3.org/1999/xhtml';
3637
export const NAMESPACE_SVG = 'http://www.w3.org/2000/svg';
3738
export const NAMESPACE_MATHML = 'http://www.w3.org/1998/Math/MathML';
3839

packages/svelte/src/internal/client/dom/blocks/svelte-element.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @import { Effect, TemplateNode } from '#client' */
2-
import { FILENAME, NAMESPACE_MATHML, NAMESPACE_SVG } from '../../../../constants.js';
2+
import { FILENAME, NAMESPACE_SVG } from '../../../../constants.js';
33
import {
44
hydrate_next,
55
hydrate_node,
@@ -28,7 +28,7 @@ import { is_raw_text_element } from '../../../../utils.js';
2828
* @param {Comment | Element} node
2929
* @param {() => string} get_tag
3030
* @param {boolean} is_svg
31-
* @param {undefined | ((element: Element, anchor: Node | null, preserve_attribute_case: boolean, is_custom_element: boolean) => void)} render_fn,
31+
* @param {undefined | ((element: Element, anchor: Node | null) => void)} render_fn,
3232
* @param {undefined | (() => string)} get_namespace
3333
* @param {undefined | [number, number]} location
3434
* @returns {void}
@@ -137,17 +137,11 @@ export function element(node, get_tag, is_svg, render_fn, get_namespace, locatio
137137
}
138138
}
139139

140-
var is_custom_element = element.nodeName.includes('-');
141-
var preserve_attribute_case =
142-
is_custom_element ||
143-
element.namespaceURI === NAMESPACE_SVG ||
144-
element.namespaceURI === NAMESPACE_MATHML;
145-
146140
// `child_anchor` is undefined if this is a void element, but we still
147141
// need to call `render_fn` in order to run actions etc. If the element
148142
// contains children, it's a user error (which is warned on elsewhere)
149143
// and the DOM will be silently discarded
150-
render_fn(element, child_anchor, preserve_attribute_case, is_custom_element);
144+
render_fn(element, child_anchor);
151145
}
152146

153147
// we do this after calling `render_fn` so that child effects don't override `nodes.end`

packages/svelte/src/internal/client/dom/elements/attributes.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from '../../runtime.js';
1616
import { clsx } from '../../../shared/attributes.js';
1717
import { set_class } from './class.js';
18+
import { NAMESPACE_HTML, NAMESPACE_MATHML } from '../../../../constants.js';
1819

1920
export const CLASS = Symbol('class');
2021
export const STYLE = Symbol('style');
@@ -261,20 +262,13 @@ export function set_custom_element_data(node, prop, value) {
261262
* @param {Record<string | symbol, any> | undefined} prev
262263
* @param {Record<string | symbol, any>} next New attributes - this function mutates this object
263264
* @param {string} [css_hash]
264-
* @param {boolean} [preserve_attribute_case]
265-
* @param {boolean} [is_custom_element]
266265
* @param {boolean} [skip_warning]
267266
* @returns {Record<string, any>}
268267
*/
269-
export function set_attributes(
270-
element,
271-
prev,
272-
next,
273-
css_hash,
274-
preserve_attribute_case = false,
275-
is_custom_element = false,
276-
skip_warning = false
277-
) {
268+
export function set_attributes(element, prev, next, css_hash, skip_warning = false) {
269+
var is_custom_element = element.nodeName.includes('-');
270+
var preserve_attribute_case = is_custom_element || element.namespaceURI !== NAMESPACE_HTML;
271+
278272
// If we're hydrating but the custom element is from Svelte, and it already scaffolded,
279273
// then it might run block logic in hydration mode, which we have to prevent.
280274
let is_hydrating_custom_element = hydrating && is_custom_element;

0 commit comments

Comments
 (0)