Skip to content

Commit e3d277b

Browse files
fix: visit synthetic value node during ssr (#17824)
Closes #17821 ### Before submitting the PR, please make sure you do the following - [x] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs - [x] Prefix your PR title with `feat:`, `fix:`, `chore:`, or `docs:`. - [x] This message body should clearly illustrate what problems it solves. - [x] Ideally, include a test that fails without this PR but passes with it. - [x] If this PR changes code within `packages/svelte/src`, add a changeset (`npx changeset`). ### Tests and linting - [x] Run the tests with `pnpm test` and lint the project with `pnpm lint`
1 parent a10cf95 commit e3d277b

6 files changed

Lines changed: 32 additions & 1 deletion

File tree

.changeset/itchy-carpets-watch.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: visit synthetic value node during ssr

packages/svelte/src/compiler/phases/3-transform/server/visitors/RegularElement.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export function RegularElement(node, context) {
126126

127127
if (node.metadata.synthetic_value_node) {
128128
body = optimiser.transform(
129-
node.metadata.synthetic_value_node.expression,
129+
/** @type {Expression} */ (context.visit(node.metadata.synthetic_value_node.expression)),
130130
node.metadata.synthetic_value_node.metadata.expression
131131
);
132132
} else {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!--[--><select><option>Dog</option><option>cat</option></select><!--]-->
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
import { writable } from 'svelte/store';
3+
4+
const value = writable('dog');
5+
const label = writable('Dog');
6+
</script>
7+
8+
<select bind:value={$value}>
9+
<option>{$label}</option>
10+
<option>cat</option>
11+
</select>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!--[--><select><option disabled="" value="" selected="">placeholder</option><option value="a">A</option><option value="b">B</option></select><!--]-->
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script>
2+
import { readable } from 'svelte/store';
3+
4+
const t = readable((/** @type {string} */ key) => key);
5+
6+
let value = $state('');
7+
</script>
8+
9+
<select bind:value>
10+
<option disabled value="">{$t('placeholder')}</option>
11+
<option value="a">A</option>
12+
<option value="b">B</option>
13+
</select>

0 commit comments

Comments
 (0)