Skip to content

Commit 2460370

Browse files
committed
merge main
2 parents 497ef13 + 4a26edf commit 2460370

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

.changeset/curvy-carrots-prove.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: account for mounting when `select_option` in `attribute_effect`

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ export function attribute_effect(
491491
var current = set_attributes(element, prev, next, css_hash, skip_warning);
492492

493493
if (inited && is_select && 'value' in next) {
494-
select_option(/** @type {HTMLSelectElement} */ (element), next.value, false);
494+
select_option(/** @type {HTMLSelectElement} */ (element), next.value);
495495
}
496496

497497
for (let symbol of Object.getOwnPropertySymbols(effects)) {
@@ -516,7 +516,7 @@ export function attribute_effect(
516516
var select = /** @type {HTMLSelectElement} */ (element);
517517

518518
effect(() => {
519-
select_option(select, /** @type {Record<string | symbol, any>} */ (prev).value);
519+
select_option(select, /** @type {Record<string | symbol, any>} */ (prev).value, true);
520520
init_select(select);
521521
});
522522
}

packages/svelte/src/internal/client/dom/elements/bindings/select.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import * as w from '../../../warnings.js';
99
* @template V
1010
* @param {HTMLSelectElement} select
1111
* @param {V} value
12-
* @param {boolean} [mounting]
12+
* @param {boolean} mounting
1313
*/
14-
export function select_option(select, value, mounting) {
14+
export function select_option(select, value, mounting = false) {
1515
if (select.multiple) {
1616
// If value is null or undefined, keep the selection as is
1717
if (value == undefined) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ok, test } from '../../test';
2+
3+
export default test({
4+
async test({ assert, target, instance }) {
5+
const select = target.querySelector('select');
6+
ok(select);
7+
assert.equal(select.selectedIndex, 1);
8+
}
9+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
let others = {onclick: ()=> {}}
3+
</script>
4+
5+
<select {...others}>
6+
<option>o1</option>
7+
<option selected>o2</option>
8+
</select>

0 commit comments

Comments
 (0)