Skip to content

Commit 834cd91

Browse files
fix: account for mounting when select_option in attribute_effect (#16309)
1 parent c3348ae commit 834cd91

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,10 @@ export function attribute_effect(
514514

515515
if (is_select) {
516516
var select = /** @type {HTMLSelectElement} */ (element);
517-
517+
var mounting = true;
518518
effect(() => {
519-
select_option(select, /** @type {Record<string | symbol, any>} */ (prev).value);
519+
select_option(select, /** @type {Record<string | symbol, any>} */ (prev).value, mounting);
520+
mounting = false;
520521
init_select(select);
521522
});
522523
}
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)