fix: account for mounting when `select_option` in `attribute_effect` (#16309)

pull/16312/head
Paolo Ricciuti 2 months ago committed by GitHub
parent c3348aea06
commit 834cd91b36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: account for mounting when `select_option` in `attribute_effect`

@ -514,9 +514,10 @@ export function attribute_effect(
if (is_select) {
var select = /** @type {HTMLSelectElement} */ (element);
var mounting = true;
effect(() => {
select_option(select, /** @type {Record<string | symbol, any>} */ (prev).value);
select_option(select, /** @type {Record<string | symbol, any>} */ (prev).value, mounting);
mounting = false;
init_select(select);
});
}

@ -0,0 +1,9 @@
import { ok, test } from '../../test';
export default test({
async test({ assert, target, instance }) {
const select = target.querySelector('select');
ok(select);
assert.equal(select.selectedIndex, 1);
}
});

@ -0,0 +1,8 @@
<script>
let others = {onclick: ()=> {}}
</script>
<select {...others}>
<option>o1</option>
<option selected>o2</option>
</select>
Loading…
Cancel
Save