Repository: sveltejs/svelte
File: packages/svelte/src/internal/client/dom/elements/attributes.js (JavaScript)

Code before:
					delegate([event_name]);
				}
			} else if (delegated) {
				// @ts-ignore
				element[`__${event_name}`] = undefined;
			}
		} else if (key === 'style' && value != null) {
			element.style.cssText = value + '';
		} else if (key === 'autofocus') {
			autofocus(/** @type {HTMLElement} */ (element), Boolean(value));
		} else if (key === '__value' || (key === 'value' && value != null)) {
			// @ts-ignore
			element.value = element[key] = element.__value = value;
		} else if (key === 'selected' && is_option_element) {
			set_selected(/** @type {HTMLOptionElement} */ (element), value);
		} else {
			var name = key;
			if (!preserve_attribute_case) {
				name = normalize_attribute(name);
			}
			let is_default_value_or_checked = name === 'defaultValue' || name === 'defaultChecked';

			if (value == null && !is_custom_element && !is_default_value_or_checked) {
				attributes[key] = null;
				// if we remove the value/checked attributes this also for some reasons reset
				// the default value so we need to keep track of it and reassign it after the remove
				let default_value_reset = /**@type {HTMLInputElement}*/ (element).defaultValue;
				let default_checked_reset = /**@type {HTMLInputElement}*/ (element).defaultChecked;
				element.removeAttribute(key);
				if (key === 'value') {
					/**@type {HTMLInputElement}*/ (element).defaultValue = default_value_reset;
				} else if (key === 'checked') {
					/**@type {HTMLInputElement}*/ (element).defaultChecked = default_checked_reset;
				}
			} else if (
				is_default_value_or_checked ||
				(setters.includes(name) && (is_custom_element || typeof value !== 'string'))
			) {
				// @ts-ignore
				element[name] = value;
			} else if (typeof value !== 'function') {
				if (hydrating && (name === 'src' || name === 'href' || name === 'srcset')) {
					if (!skip_warning) check_src_in_dev_hydration(element, name, value ?? '');
				} else {
					set_attribute(element, name, value);
				}
			}
		}
		if (key === 'style' && '__styles' in element) {
			// reset styles to force style: directive to update
			element.__styles = {};

Review comment (suggestion):
Ah I see, yeah that's why - now I'm wondering if we should model this differently: Check if the dom element is an input or textarea, and if so, if we come across a `value` or `checked` attribute, skip to the setters. Not sure which solution ends up being less code.

Code after:
					delegate([event_name]);
				}
			} else if (delegated) {
				// @ts-ignore
				element[`__${event_name}`] = undefined;
			}
		} else if (key === 'style' && value != null) {
			element.style.cssText = value + '';
		} else if (key === 'autofocus') {
			autofocus(/** @type {HTMLElement} */ (element), Boolean(value));
		} else if (key === '__value' || (key === 'value' && value != null)) {
			// @ts-ignore
			element.value = element[key] = element.__value = value;
		} else if (key === 'selected' && is_option_element) {
			set_selected(/** @type {HTMLOptionElement} */ (element), value);
		} else {
			var name = key;
			if (!preserve_attribute_case) {
				name = normalize_attribute(name);
			}

			var is_default = name === 'defaultValue' || name === 'defaultChecked';

			if (value == null && !is_custom_element && !is_default) {
				attributes[key] = null;

				if (name === 'value' || name === 'checked') {
					// removing value/checked also removes defaultValue/defaultChecked — preserve
					let input = /** @type {HTMLInputElement} */ (element);

					if (name === 'value') {
						let prev = input.defaultValue;
						input.removeAttribute(name);
						input.defaultValue = prev;
					} else {
						let prev = input.defaultChecked;
						input.removeAttribute(name);
						input.defaultChecked = prev;
					}
				} else {
					element.removeAttribute(key);
				}
			} else if (
				is_default ||
				(setters.includes(name) && (is_custom_element || typeof value !== 'string'))
			) {
				// @ts-ignore
				element[name] = value;
			} else if (typeof value !== 'function') {
				if (hydrating && (name === 'src' || name === 'href' || name === 'srcset')) {
					if (!skip_warning) check_src_in_dev_hydration(element, name, value ?? '');