do not remove defaults if they are in spreads

pull/16481/head
7nik 1 month ago
parent 44ac3a9950
commit 2d17f4af36

@ -172,7 +172,16 @@ export function RegularElement(node, context) {
bindings.has('group') ||
(!bindings.has('group') && has_value_attribute))
) {
context.state.init.push(b.stmt(b.call('$.remove_input_defaults', context.state.node)));
const spreads = has_spread
? b.object(
attributes
.filter((attr) => attr.type === 'SpreadAttribute')
.map((attr) => b.spread(attr.expression))
)
: null;
context.state.init.push(
b.stmt(b.call('$.remove_input_defaults', context.state.node, spreads))
);
}
}

@ -31,14 +31,20 @@ const IS_CUSTOM_ELEMENT = Symbol('is custom element');
const IS_HTML = Symbol('is html');
/**
* The value/checked attribute in the template actually corresponds to the defaultValue property, so we need
* to remove it upon hydration to avoid a bug when someone resets the form value.
* The value/checked attribute in the template actually corresponds to the defaultValue property,
* so we need to remove it upon hydration to avoid a bug when someone resets the form value,
* unless the property is presented in the spreaded objects and is handled by `set_attributes()`
* @param {HTMLInputElement} input
* @param {Record<string, any>} [spread]
* @returns {void}
*/
export function remove_input_defaults(input) {
export function remove_input_defaults(input, spread) {
if (!hydrating) return;
if (spread && (input.type === 'checkbox' ? 'defaultChecked' : 'defaultValue') in spread) {
return;
}
var already_removed = false;
// We try and remove the default attributes later, rather than sync during hydration.

Loading…
Cancel
Save