initialize option values before initing select values

pull/16251/head
Rich Harris 3 months ago
parent 213274a75e
commit 334adc0897

@ -199,16 +199,16 @@ export function RegularElement(node, context) {
const node_id = context.state.node; const node_id = context.state.node;
/** If true, needs `__value` for inputs */
const needs_special_value_handling =
node.name === 'option' ||
node.name === 'select' ||
bindings.has('group') ||
bindings.has('checked');
if (has_spread) { if (has_spread) {
build_attribute_effect(attributes, class_directives, style_directives, context, node, node_id); build_attribute_effect(attributes, class_directives, style_directives, context, node, node_id);
} else { } else {
/** If true, needs `__value` for inputs */
const needs_special_value_handling =
node.name === 'option' ||
node.name === 'select' ||
bindings.has('group') ||
bindings.has('checked');
for (const attribute of /** @type {AST.Attribute[]} */ (attributes)) { for (const attribute of /** @type {AST.Attribute[]} */ (attributes)) {
if (is_event_attribute(attribute)) { if (is_event_attribute(attribute)) {
visit_event_attribute(attribute, context); visit_event_attribute(attribute, context);
@ -216,7 +216,6 @@ export function RegularElement(node, context) {
} }
if (needs_special_value_handling && attribute.name === 'value') { if (needs_special_value_handling && attribute.name === 'value') {
build_element_special_value_attribute(node.name, node_id, attribute, context);
continue; continue;
} }
@ -391,6 +390,21 @@ export function RegularElement(node, context) {
context.state.update.push(b.stmt(b.assignment('=', dir, dir))); context.state.update.push(b.stmt(b.assignment('=', dir, dir)));
} }
if (!has_spread && needs_special_value_handling) {
for (const attribute of /** @type {AST.Attribute[]} */ (attributes)) {
if (attribute.name === 'value') {
build_element_special_value_attribute(
node.name,
node_id,
attribute,
context,
context.state
);
break;
}
}
}
context.state.template.pop_element(); context.state.template.pop_element();
} }
@ -612,9 +626,9 @@ function build_custom_element_attribute_update_assignment(node_id, attribute, co
* @param {Identifier} node_id * @param {Identifier} node_id
* @param {AST.Attribute} attribute * @param {AST.Attribute} attribute
* @param {ComponentContext} context * @param {ComponentContext} context
* @param {ComponentClientTransformState} state
*/ */
function build_element_special_value_attribute(element, node_id, attribute, context) { function build_element_special_value_attribute(element, node_id, attribute, context, state) {
const state = context.state;
const is_select_with_value = const is_select_with_value =
// attribute.metadata.dynamic would give false negatives because even if the value does not change, // attribute.metadata.dynamic would give false negatives because even if the value does not change,
// the inner options could still change, so we need to always treat it as reactive // the inner options could still change, so we need to always treat it as reactive

Loading…
Cancel
Save