Skip to content

fix: preserve select selection with spread attributes - #18561

Merged
paoloricciuti merged 2 commits into
sveltejs:mainfrom
floze-the-genius:fix/select-spread-preserve-selection
Jul 22, 2026
Merged

paoloricciuti merged 2 commits into
sveltejs:mainfrom
floze-the-genius:fix/select-spread-preserve-selection

Conversation

@floze-the-genius

Copy link
Copy Markdown
Contributor

Fixes #18557

A <select> with spread attributes initializes the option mutation observer even when those attributes never provide a value. In that case the element has no internal __value, but the observer previously treated the missing property as an explicit undefined value and deselected every option after an option was added or removed.

Only reapply the programmatic selection when __value is actually present. This preserves the browser's current selection for spreads without a value while keeping the existing behavior for bindings, including an explicitly stored undefined value.

A runtime-legacy regression fixture covers both adding and removing an option in client and hydration modes.

Before submitting

  • References the existing issue
  • Uses a fix: title
  • Includes a regression test
  • Includes a patch changeset for svelte

Test plan

  • FILTER=select-spread-preserve-selection pnpm test runtime-legacy --maxWorkers=1 (2 tests passed: client and hydrate)
  • git diff --check
  • Full pnpm test was not run because the shared host was under resource pressure and broad test processes were explicitly avoided
  • pnpm lint and pnpm check were not run for the same reason
  • Targeted repository Prettier check was attempted, but could not start because prettier-plugin-svelte required the ungenerated packages/svelte/compiler/index.js; no broad build or dependency reinstall was run

AI disclosure

AI-assisted: the implementation, regression test, and pull request text were prepared with OpenAI Codex and reviewed by the contributor.

@pkg-svelte-dev

pkg-svelte-dev Bot commented Jul 18, 2026 •

Copy link
Copy Markdown

Install the latest version of svelte from 442556a:

pnpm add https://pkg.svelte.dev/svelte/c/442556a9e363239c47466d4dc33c82ffd58d77fd

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/svelte/pr/18561

Note

This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed.

@changeset-bot

changeset-bot Bot commented Jul 18, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 442556a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@paoloricciuti
paoloricciuti merged commit 2bace30 into sveltejs:main Jul 22, 2026
15 of 16 checks passed
@paoloricciuti

Copy link
Copy Markdown
Member

Thanks! 🧡

@github-actions github-actions Bot mentioned this pull request Jul 22, 2026
dummdidumm pushed a commit that referenced this pull request Jul 24, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## svelte@5.56.8

### Patch Changes

- fix: call `onerror` and provide a working `reset` when hydrating a
failed boundary
([#18556](#18556))

- fix: preserve select selection when spread attributes omit value
([#18561](#18561))

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
khromov added a commit to khromov/mochi that referenced this pull request Jul 29, 2026
Bumps Svelte from **5.56.7 → 5.56.8** across every workspace.

## Upstream changes

Patch release, two fixes — the first lands directly on a Mochi code
path, since the preprocessor auto-wraps every `mochi:hydrate*` island in
a `<svelte:boundary>`:

- fix: call `onerror` and provide a working `reset` when hydrating a
failed boundary
([sveltejs/svelte#18556](sveltejs/svelte#18556))
- fix: preserve select selection when spread attributes omit value
([sveltejs/svelte#18561](sveltejs/svelte#18561))

## Bump table

| Workspace | Field | From | To |
| --- | --- | --- | --- |
| `packages/mochi` | devDependencies | `^5.56.7` | `^5.56.8` |
| `packages/mochi-rsvelte` | devDependencies | `^5.56.7` | `^5.56.8` |
| `packages/site` | dependencies | `^5.56.7` | `^5.56.8` |
| `packages/demos` | dependencies | `^5.56.7` | `^5.56.8` |
| `packages/docs` | dependencies | `^5.56.7` | `^5.56.8` |
| `packages/minimal` | dependencies | `^5.56.7` | `^5.56.8` |
| `packages/minimal-rsvelte` | dependencies | `^5.56.7` | `^5.56.8` |
| `packages/support` | dependencies | `^5.56.7` | `^5.56.8` |

## Deliberately not changed

- **`packages/mochi` `peerDependencies.svelte` stays at `^5.56.6`.**
It's a floor for published consumers and already admits 5.56.8; raising
it would force an upgrade for no API reason. Since published
`mochi-framework` carries Svelte only as a devDependency plus this
unchanged peer range, nothing consumer-visible moved — hence
`chore(deps):` rather than `fix(deps):`, and no release is warranted.
- Scope is Svelte only, not a full dependency sweep. Also currently
outdated and left alone: `@lucide/svelte` (1.25.0 → 1.27.0),
`@rsvelte/vite-plugin-svelte-native` (0.2.8 → 0.3.1), `svelte-check`
(4.7.3 → 4.7.4, exact-pinned because it carries a patch keyed on the
version), `typescript` (6.0.3 → 7.0.2).

The `bun.lock` diff is Svelte-only; the one removed `svelte/devalue`
entry is a dedupe artifact (devalue is now satisfied from the root).

## Verification

- **`bun run syncpack`** — ✅ no issues; cross-workspace agreement holds,
including the unchanged peer range.
- **`bun run checks`** (lint:fix + format + typecheck + test) — ✅ all
four stages green. Typecheck 0 errors across all workspaces; tests
142/142 mochi-framework files, 9/9 site, 2/2 support,
demos/minimal/minimal-rsvelte all green, 0 failures.
- **Clean reinstall + dedupe** — `rm -rf node_modules
packages/*/node_modules && bun install`.
`packages/*/node_modules/svelte` is empty and `node_modules/.bun` is
absent, so there is exactly one hoisted `svelte@5.56.8`. (Duplicate
copies mean two context maps and break `getContext` across the island
boundary — invisible to CI.)
- **`bun run build`** — ✅ output byte-identical to the pre-bump baseline
apart from timings. No optimization skipped, no shake fallback:

  | | before | after |
  | --- | --- | --- |
  | `svelte-shaker` (site) | slimmed 33 of 163 | slimmed 33 of 163 |
| site | 65 pages · 245 client files · 12 public · 7 image assets · 2
email templates | identical |
  | demos | 10 pages · 32 client files | identical |
  | support | 2 pages · 19 client files · 1 email template | identical |
| minimal / minimal-rsvelte | 1 page · 10 client files each | identical
|

  Per-file bundle sizes in the build listing are unchanged too.

- **Browser smoke test** (`PORT=4444 bun run dev:site`, driven via
chrome-devtools):
  - `/` — no console errors/warnings.
  - `/docs/queues/` — no console errors/warnings.
- `/demos/error-boundaries/` — the demo most relevant to #18556. All
five scenarios render their expected fallbacks (user-written boundary,
`mochi:hydrate` SSR throw, `mochi:hydrate` client throw, `mochi:defer`
server-island throw, healthy server island with an inner throwing
`mochi:hydrate` child). All 22 requests 200, including both
`/_mochi/island/*` fetches. The only console output is the demo's
intentional `ThrowOnClient` failure. Debug bar reports **Svelte
5.56.8**.
- `/demos/nested-islands/` — clean console, all four `/_mochi/island/*`
fetches 200.
- `/demos/is-hydratable/` — clean console, both island fetches 200. This
is the canary for the duplicate-copy failure mode (`isHydratable()` is
its first casualty), so it independently confirms the dedupe.
- **`bun run cli-test`** — ✅ pass (scaffold, install, test, typecheck).
`minimal` and `demos` both moved and double as `create-mochi` template
sources.
renovate Bot added a commit to cigaleapp/cigale that referenced this pull request Aug 2, 2026
##### [v5.56.8](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#5568)

##### Patch Changes

- fix: call `onerror` and provide a working `reset` when hydrating a failed boundary ([#18556](sveltejs/svelte#18556))

- fix: preserve select selection when spread attributes omit value ([#18561](sveltejs/svelte#18561))
##### [v5.56.7](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#5567)

##### Patch Changes

- chore: provide `indent` option for `print` ([#18474](sveltejs/svelte#18474))
renovate Bot added a commit to cigaleapp/cigale that referenced this pull request Aug 2, 2026
##### [v5.56.8](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#5568)

##### Patch Changes

- fix: call `onerror` and provide a working `reset` when hydrating a failed boundary ([#18556](sveltejs/svelte#18556))

- fix: preserve select selection when spread attributes omit value ([#18561](sveltejs/svelte#18561))
##### [v5.56.7](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#5567)

##### Patch Changes

- chore: provide `indent` option for `print` ([#18474](sveltejs/svelte#18474))
renovate Bot added a commit to cigaleapp/cigale that referenced this pull request Aug 2, 2026
##### [v5.56.8](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#5568)

##### Patch Changes

- fix: call `onerror` and provide a working `reset` when hydrating a failed boundary ([#18556](sveltejs/svelte#18556))

- fix: preserve select selection when spread attributes omit value ([#18561](sveltejs/svelte#18561))
##### [v5.56.7](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#5567)

##### Patch Changes

- chore: provide `indent` option for `print` ([#18474](sveltejs/svelte#18474))
renovate Bot added a commit to cigaleapp/cigale that referenced this pull request Aug 2, 2026
##### [v5.56.8](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#5568)

##### Patch Changes

- fix: call `onerror` and provide a working `reset` when hydrating a failed boundary ([#18556](sveltejs/svelte#18556))

- fix: preserve select selection when spread attributes omit value ([#18561](sveltejs/svelte#18561))
##### [v5.56.7](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#5567)

##### Patch Changes

- chore: provide `indent` option for `print` ([#18474](sveltejs/svelte#18474))
renovate Bot added a commit to cigaleapp/cigale that referenced this pull request Aug 2, 2026
##### [v5.56.8](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#5568)

##### Patch Changes

- fix: call `onerror` and provide a working `reset` when hydrating a failed boundary ([#18556](sveltejs/svelte#18556))

- fix: preserve select selection when spread attributes omit value ([#18561](sveltejs/svelte#18561))
##### [v5.56.7](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#5567)

##### Patch Changes

- chore: provide `indent` option for `print` ([#18474](sveltejs/svelte#18474))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Selection lost on <select> with spread attributes when options change after mount

2 participants