Skip to content

Commit c4851b1

Browse files
committed
tweak
1 parent ce373ff commit c4851b1

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -358,16 +358,15 @@ export function set_attributes(
358358

359359
if (value == null && !is_custom_element && !is_default_value_or_checked) {
360360
attributes[key] = null;
361-
// if we remove the value/checked attributes this also for some reasons reset
362-
// the default value so we need to keep track of it and reassign it after the remove
363-
let default_value_reset = /**@type {HTMLInputElement}*/ (element).defaultValue;
364-
let default_checked_reset = /**@type {HTMLInputElement}*/ (element).defaultChecked;
361+
362+
// resetting value/checked also resets defaultValue/defaultChecked — preserve it
363+
const prop = name === 'value' ? 'defaultValue' : 'defaultChecked';
364+
const prev = /** @type {HTMLInputElement} */ (element)[prop];
365+
365366
element.removeAttribute(key);
366-
if (key === 'value') {
367-
/**@type {HTMLInputElement}*/ (element).defaultValue = default_value_reset;
368-
} else if (key === 'checked') {
369-
/**@type {HTMLInputElement}*/ (element).defaultChecked = default_checked_reset;
370-
}
367+
368+
// @ts-expect-error
369+
element[prop] = prev;
371370
} else if (
372371
is_default_value_or_checked ||
373372
(setters.includes(name) && (is_custom_element || typeof value !== 'string'))

0 commit comments

Comments
 (0)