Skip to content

Commit b8eb68f

Browse files
committed
better fix
1 parent dd30558 commit b8eb68f

File tree

2 files changed

+24
-36
lines changed

2 files changed

+24
-36
lines changed

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

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { escape_html } from '../../../../../escaping.js';
77
import {
88
is_boolean_attribute,
9-
get_dom_property,
9+
is_dom_property,
1010
is_load_error_element,
1111
is_void
1212
} from '../../../../../utils.js';
@@ -557,31 +557,27 @@ function build_element_attribute_update_assignment(element, node_id, attribute,
557557
update = b.stmt(b.call('$.set_value', node_id, value));
558558
} else if (name === 'checked') {
559559
update = b.stmt(b.call('$.set_checked', node_id, value));
560+
} else if (is_dom_property(name)) {
561+
update = b.stmt(b.assignment('=', b.member(node_id, name), value));
560562
} else {
561-
const dom_property = get_dom_property(name);
562-
563-
if (dom_property) {
564-
update = b.stmt(b.assignment('=', b.member(node_id, dom_property), value));
565-
} else {
566-
if (name === 'style' && attribute.metadata.expression.has_state && has_call) {
567-
// ensure we're not creating a separate template effect for this so that
568-
// potential style directives are added to the same effect and therefore always apply
569-
const id = b.id(state.scope.generate('style_derived'));
570-
state.init.push(b.const(id, create_derived(state, b.thunk(value))));
571-
value = b.call('$.get', id);
572-
has_call = false;
573-
}
574-
const callee = name.startsWith('xlink') ? '$.set_xlink_attribute' : '$.set_attribute';
575-
update = b.stmt(
576-
b.call(
577-
callee,
578-
node_id,
579-
b.literal(name),
580-
value,
581-
is_ignored(element, 'hydration_attribute_changed') && b.true
582-
)
583-
);
563+
if (name === 'style' && attribute.metadata.expression.has_state && has_call) {
564+
// ensure we're not creating a separate template effect for this so that
565+
// potential style directives are added to the same effect and therefore always apply
566+
const id = b.id(state.scope.generate('style_derived'));
567+
state.init.push(b.const(id, create_derived(state, b.thunk(value))));
568+
value = b.call('$.get', id);
569+
has_call = false;
584570
}
571+
const callee = name.startsWith('xlink') ? '$.set_xlink_attribute' : '$.set_attribute';
572+
update = b.stmt(
573+
b.call(
574+
callee,
575+
node_id,
576+
b.literal(name),
577+
value,
578+
is_ignored(element, 'hydration_attribute_changed') && b.true
579+
)
580+
);
585581
}
586582

587583
if (attribute.metadata.expression.has_state) {

packages/svelte/src/utils.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ const ATTRIBUTE_ALIASES = {
192192
ismap: 'isMap',
193193
nomodule: 'noModule',
194194
playsinline: 'playsInline',
195-
readonly: 'readOnly'
195+
readonly: 'readOnly',
196+
srcobject: 'srcObject'
196197
};
197198

198199
/**
@@ -216,20 +217,11 @@ const DOM_PROPERTIES = [
216217
'srcObject'
217218
];
218219

219-
/** @type {Map<string, string>} */
220-
let DOM_PROPERTIES_MAP;
221-
222220
/**
223221
* @param {string} name
224-
* @returns {string | undefined}
225222
*/
226-
export function get_dom_property(name) {
227-
if (!DOM_PROPERTIES_MAP) {
228-
DOM_PROPERTIES_MAP = new Map(
229-
DOM_PROPERTIES.map((property) => [property.toLowerCase(), property])
230-
);
231-
}
232-
return DOM_PROPERTIES_MAP.get(name);
223+
export function is_dom_property(name) {
224+
return DOM_PROPERTIES.includes(name);
233225
}
234226

235227
/**

0 commit comments

Comments
 (0)