Skip to content

fix: avoid compiler crash on <select value> with a sibling block#18422

Open
sarathfrancis90 wants to merge 1 commit into
sveltejs:mainfrom
sarathfrancis90:fix-select-static-value
Open

fix: avoid compiler crash on <select value> with a sibling block#18422
sarathfrancis90 wants to merge 1 commit into
sveltejs:mainfrom
sarathfrancis90:fix-select-static-value

Conversation

@sarathfrancis90

Copy link
Copy Markdown

A <select> with a static value attribute crashes the compiler in client mode when it has a sibling block, e.g.:

{#if false}{/if}
<select value="b">
	<option>a</option>
	<option>b</option>
</select>

This throws TypeError: Cannot read properties of null (reading 'type') from codegen rather than compiling. The sibling block is what routes the select through is_static_element, which classified it as fully static so no element reference was created for it. The regular-element visitor still needs that reference to emit the special select.__value/value assignment, so it ended up building null.value = ....

input, textarea and option already opt out of the static fast path for their value attributes — select just needs the same. With the fix it compiles and the matching option is selected.

Tests and linting

Added a runtime-runes sample that reproduces the crash and asserts the right option is selected; it fails without the fix and passes with it. Full pnpm test, pnpm lint and pnpm check are green. Added a changeset.

… element

A `<select value="...">` whose contents are otherwise static was classified as a
static element, so no element reference was created for it. The regular-element
visitor still needs that reference to emit the special `select.__value` / value
assignment, so it tried to build `null.value = ...` and the compiler threw a raw
`TypeError: Cannot read properties of null` from codegen instead of producing
output. This only surfaced when the select had a sibling block (e.g. an `{#if}`),
which is what routes it through the static-element fast path.

`input`, `textarea` and `option` already opt out of the static fast path for
their value attributes; `select` needs the same treatment.
@changeset-bot

changeset-bot Bot commented Jun 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b4a0877

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

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.

1 participant