Repository: sveltejs/svelte (2025-07-06T12:20:36Z)

Issue:
`<select>` doesn't respect `selected` attribute when spreading props
### Describe the bug

When you have a basic select tag, and give it an {...others} spread (like it's in a component and receives some properties), it will no longer show any option, regardless of it having the 'selected' property or not.

I linked the playground repro, but just to have it here as well, because it's so simple to visualize:

```svelte
<script>
	let others = {onclick: ()=> console.log('aaa')}
</script>

<select>
	<option>o1</option>
	<option selected>o2</option>
</select>

<select {...others}>
	<option>o1</option>
	<option selected>o2</option>
</select>
```

First select will have 'o2' selected, which is correct, the second select will have nothing selected. Only by removing the spread 'others' will it work again. Clicking on it will print the console, so the spread itself is working.

I'm not exactly sure when this started happening. I keep rolling back versions of svelte to no avail, but I know it definitely worked a few weeks ago when my full pipeline ran. I put "blocking an upgrade" because I will definitely revert to a working version once I... you know... actually find it.

### Reproduction

https://svelte.dev/playground/187497f0959046c19ab25f2129e9a3ae?version=latest

### Logs

```shell

```

### System Info

```shell
Reproducible on all browsers, as I ran playwright tests on safari, chrome and firefox. Also ran it on chrome and firefox on Windows 11
```

### Severity

blocking an upgrade


Discussion:
This appears to be some sort of regression from #16249. 
Are we sure it's not from this?

https://github.com/sveltejs/svelte/pull/16251
Appears to work in [5.34.8](https://svelte.dev/playground/187497f0959046c19ab25f2129e9a3ae?version=5.34.8#H4sIAAAAAAAAA62PsU4DMQyGXyXy0lY65QRjlEbiGTpyDGnqQkSwo9gFqtO9O7oeVTswslmff3-2R6D4geBghwWTGmyNG3RwzAUF3PMIeq5zfwbQXdNPtVr5xKIz20fBv3hiUiQVcOAX6LhqZhLTToTSh4G8pJarhoEGLaiG9Q2bmK0ZmVLJ6d2Z9WYbTGISLmgLv65XMcbVZhrI97dp8nL54GLyy57AD77_Le-wWZJ4CPx41_f9zXC1mdFau9w0_YsZOlD8VnDaTji9dKAxl69MB3DHWASnHzQdL-mRAQAA)... 
> Appears to work in [5.34.8](https://svelte.dev/playground/187497f0959046c19ab25f2129e9a3ae?version=5.34.8#H4sIAAAAAAAAA62PsU4DMQyGXyXy0lY65QRjlEbiGTpyDGnqQkSwo9gFqtO9O7oeVTswslmff3-2R6D4geBghwWTGmyNG3RwzAUF3PMIeq5zfwbQXdNPtVr5xKIz20fBv3hiUiQVcOAX6LhqZhLTToTSh4G8pJarhoEGLaiG9Q2bmK0ZmVLJ6d2Z9WYbTGISLmgLv65XMcbVZhrI97dp8nL54GLyy57AD77_Le-wWZJ4CPx41_f9zXC1mdFau9w0_YsZOlD8VnDaTji9dKAxl69MB3DHWASnHzQdL-mRAQAA)... 

Yeah, can confirm. I was actually messing up my versioning, that's why it didn't work as I was going to older versions. But with 34.8 it works. 
Pretty sure it's from https://github.com/sveltejs/svelte/pull/16251 - it didn't have a changeset and was part of 5.34.8
Yea, just hit this snag myself after upgrading to 5.35.1.

Is currently preventing me from upgrading.



Patch:
diff --git a/.changeset/curvy-carrots-prove.md b/.changeset/curvy-carrots-prove.md
new file mode 100644
index 000000000000..77239901790d
--- /dev/null
+++ b/.changeset/curvy-carrots-prove.md
@@ -0,0 +1,5 @@
+---
+'svelte': patch
+---
+
+fix: account for mounting when `select_option` in `attribute_effect`
diff --git a/packages/svelte/src/internal/client/dom/elements/attributes.js b/packages/svelte/src/internal/client/dom/elements/attributes.js
index 5db685cf3e90..c96338778f44 100644
--- a/packages/svelte/src/internal/client/dom/elements/attributes.js
+++ b/packages/svelte/src/internal/client/dom/elements/attributes.js
@@ -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);
 		});
 	}


Test patch:
diff --git a/packages/svelte/tests/runtime-runes/samples/select-spread-option-selected/_config.js b/packages/svelte/tests/runtime-runes/samples/select-spread-option-selected/_config.js
new file mode 100644
index 000000000000..50da3ac09567
--- /dev/null
+++ b/packages/svelte/tests/runtime-runes/samples/select-spread-option-selected/_config.js
@@ -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);
+	}
+});
diff --git a/packages/svelte/tests/runtime-runes/samples/select-spread-option-selected/main.svelte b/packages/svelte/tests/runtime-runes/samples/select-spread-option-selected/main.svelte
new file mode 100644
index 000000000000..e5fc6c553538
--- /dev/null
+++ b/packages/svelte/tests/runtime-runes/samples/select-spread-option-selected/main.svelte
@@ -0,0 +1,8 @@
+<script>
+	let others = {onclick: ()=> {}}
+</script>
+
+<select {...others}>
+	<option>o1</option>
+	<option selected>o2</option>
+</select>