pull/16251/head
Rich Harris 3 months ago
parent d89f3184eb
commit 58918e38e9

@ -665,10 +665,6 @@ function build_element_special_value_attribute(element, node_id, attribute, cont
: inner_assignment : inner_assignment
); );
if (is_select_with_value) {
state.init.push(b.stmt(b.call('$.init_select', node_id)));
}
if (has_state) { if (has_state) {
const id = b.id(state.scope.generate(`${node_id.name}_value`)); const id = b.id(state.scope.generate(`${node_id.name}_value`));
@ -682,4 +678,8 @@ function build_element_special_value_attribute(element, node_id, attribute, cont
} else { } else {
state.init.push(update); state.init.push(update);
} }
if (is_select_with_value) {
state.init.push(b.stmt(b.call('$.init_select', node_id)));
}
} }

@ -515,11 +515,9 @@ export function attribute_effect(
if (is_select) { if (is_select) {
var select = /** @type {HTMLSelectElement} */ (element); var select = /** @type {HTMLSelectElement} */ (element);
if (!inited) { queue_micro_task(() => {
effect(() => { select_option(select, /** @type {Record<string | symbol, any>} */ (prev).value);
select_option(select, /** @type {Record<string | symbol, any>} */ (prev).value); });
});
}
init_select(select); init_select(select);
} }

@ -1,9 +1,9 @@
import { effect } from '../../../reactivity/effects.js'; import { effect } from '../../../reactivity/effects.js';
import { listen_to_event_and_reset_event } from './shared.js'; import { listen_to_event_and_reset_event } from './shared.js';
import { untrack } from '../../../runtime.js';
import { is } from '../../../proxy.js'; import { is } from '../../../proxy.js';
import { is_array } from '../../../../shared/utils.js'; import { is_array } from '../../../../shared/utils.js';
import * as w from '../../../warnings.js'; import * as w from '../../../warnings.js';
import { queue_micro_task } from '../../task.js';
/** /**
* Selects the correct option(s) (depending on whether this is a multiple select) * Selects the correct option(s) (depending on whether this is a multiple select)
@ -51,11 +51,10 @@ export function select_option(select, value, mounting) {
* current selection to the dom when it changes. Such * current selection to the dom when it changes. Such
* changes could for example occur when options are * changes could for example occur when options are
* inside an `#each` block. * inside an `#each` block.
* @template V
* @param {HTMLSelectElement} select * @param {HTMLSelectElement} select
*/ */
export function init_select(select) { export function init_select(select) {
effect(() => { queue_micro_task(() => {
var observer = new MutationObserver(() => { var observer = new MutationObserver(() => {
// @ts-ignore // @ts-ignore
var value = select.__value; var value = select.__value;

Loading…
Cancel
Save