Skip to content

Commit d7caac0

Browse files
committed
stash lookup
1 parent a829e59 commit d7caac0

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

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

+24-11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import { NAMESPACE_HTML } from '../../../../constants.js';
2020
export const CLASS = Symbol('class');
2121
export const STYLE = Symbol('style');
2222

23+
const IS_CUSTOM_ELEMENT = Symbol('is custom element');
24+
const IS_HTML = Symbol('is html');
25+
2326
/**
2427
* The value/checked attribute in the template actually corresponds to the defaultValue property, so we need
2528
* to remove it upon hydration to avoid a bug when someone resets the form value.
@@ -64,8 +67,7 @@ export function remove_input_defaults(input) {
6467
* @param {any} value
6568
*/
6669
export function set_value(element, value) {
67-
// @ts-expect-error
68-
var attributes = (element.__attributes ??= {});
70+
var attributes = get_attributes(element);
6971

7072
if (
7173
attributes.value ===
@@ -88,8 +90,7 @@ export function set_value(element, value) {
8890
* @param {boolean} checked
8991
*/
9092
export function set_checked(element, checked) {
91-
// @ts-expect-error
92-
var attributes = (element.__attributes ??= {});
93+
var attributes = get_attributes(element);
9394

9495
if (
9596
attributes.checked ===
@@ -152,8 +153,7 @@ export function set_default_value(element, value) {
152153
* @param {boolean} [skip_warning]
153154
*/
154155
export function set_attribute(element, attribute, value, skip_warning) {
155-
// @ts-expect-error
156-
var attributes = (element.__attributes ??= {});
156+
var attributes = get_attributes(element);
157157

158158
if (hydrating) {
159159
attributes[attribute] = element.getAttribute(attribute);
@@ -266,8 +266,10 @@ export function set_custom_element_data(node, prop, value) {
266266
* @returns {Record<string, any>}
267267
*/
268268
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;
269+
var attributes = get_attributes(element);
270+
271+
var is_custom_element = attributes[IS_CUSTOM_ELEMENT];
272+
var preserve_attribute_case = !attributes[IS_HTML];
271273

272274
// If we're hydrating but the custom element is from Svelte, and it already scaffolded,
273275
// then it might run block logic in hydration mode, which we have to prevent.
@@ -293,9 +295,6 @@ export function set_attributes(element, prev, next, css_hash, skip_warning = fal
293295

294296
var setters = get_setters(element);
295297

296-
// @ts-expect-error
297-
var attributes = /** @type {Record<string, unknown>} **/ (element.__attributes ??= {});
298-
299298
// since key is captured we use const
300299
for (const key in next) {
301300
// let instead of var because referenced in a closure
@@ -442,6 +441,20 @@ export function set_attributes(element, prev, next, css_hash, skip_warning = fal
442441
return current;
443442
}
444443

444+
/**
445+
*
446+
* @param {Element} element
447+
*/
448+
function get_attributes(element) {
449+
return /** @type {Record<string | symbol, unknown>} **/ (
450+
// @ts-expect-error
451+
element.__attributes ??= {
452+
[IS_CUSTOM_ELEMENT]: element.nodeName.includes('-'),
453+
[IS_HTML]: element.namespaceURI === NAMESPACE_HTML
454+
}
455+
);
456+
}
457+
445458
/** @type {Map<string, string[]>} */
446459
var setters_cache = new Map();
447460

0 commit comments

Comments
 (0)