Skip to content

Commit 25762b1

Browse files
committed
side-effects agin
1 parent 96f8160 commit 25762b1

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

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

Lines changed: 24 additions & 20 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-
DOM_PROPERTIES_MAP,
9+
get_dom_property,
1010
is_load_error_element,
1111
is_void
1212
} from '../../../../../utils.js';
@@ -557,27 +557,31 @@ 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 (DOM_PROPERTIES_MAP.has(name)) {
561-
update = b.stmt(b.assignment('=', b.member(node_id, DOM_PROPERTIES_MAP.get(name)), value));
562560
} else {
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;
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+
);
570584
}
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-
);
581585
}
582586

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

packages/svelte/src/utils.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,18 @@ const DOM_PROPERTIES = [
216216
'srcObject'
217217
];
218218

219-
export const DOM_PROPERTIES_MAP = new Map(
219+
const DOM_PROPERTIES_MAP = new Map(
220220
DOM_PROPERTIES.map((property) => [property.toLowerCase(), property])
221221
);
222222

223+
/**
224+
* @param {string} name
225+
* @returns {string | undefined}
226+
*/
227+
export function get_dom_property(name) {
228+
return DOM_PROPERTIES_MAP.get(name);
229+
}
230+
223231
/**
224232
* Subset of delegated events which should be passive by default.
225233
* These two are already passive via browser defaults on window, document and body.

0 commit comments

Comments
 (0)