From 3af1ad2a97de11ff1cc2c1718deb9d9f51bf7738 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 1 Dec 2025 13:47:34 -0500 Subject: [PATCH] fix: allow `$props.id()` to occur after an `await` --- .changeset/sad-paths-build.md | 5 +++++ .../svelte/src/compiler/phases/2-analyze/index.js | 5 +++++ .../runtime-runes/samples/async-props-id/_config.js | 11 +++++++++++ .../runtime-runes/samples/async-props-id/main.svelte | 6 ++++++ 4 files changed, 27 insertions(+) create mode 100644 .changeset/sad-paths-build.md create mode 100644 packages/svelte/tests/runtime-runes/samples/async-props-id/_config.js create mode 100644 packages/svelte/tests/runtime-runes/samples/async-props-id/main.svelte diff --git a/.changeset/sad-paths-build.md b/.changeset/sad-paths-build.md new file mode 100644 index 000000000000..f64d6f766cbd --- /dev/null +++ b/.changeset/sad-paths-build.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: allow `$props.id()` to occur after an `await` diff --git a/packages/svelte/src/compiler/phases/2-analyze/index.js b/packages/svelte/src/compiler/phases/2-analyze/index.js index e44cf23ff5d2..6d23e4d26504 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/index.js +++ b/packages/svelte/src/compiler/phases/2-analyze/index.js @@ -1105,6 +1105,11 @@ function calculate_blockers(instance, scopes, analysis) { functions.push(node); } else if (node.type === 'VariableDeclaration') { for (const declarator of node.declarations) { + if (get_rune(declarator.init, instance.scope) === '$props.id') { + // special case + continue; + } + if ( declarator.init?.type === 'ArrowFunctionExpression' || declarator.init?.type === 'FunctionExpression' diff --git a/packages/svelte/tests/runtime-runes/samples/async-props-id/_config.js b/packages/svelte/tests/runtime-runes/samples/async-props-id/_config.js new file mode 100644 index 000000000000..3c6a6ed247c6 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/async-props-id/_config.js @@ -0,0 +1,11 @@ +import { tick } from 'svelte'; +import { test } from '../../test'; + +export default test({ + ssrHtml: `

s1

`, + + async test({ assert, target, variant }) { + await tick(); + assert.htmlEqual(target.innerHTML, variant === 'hydrate' ? '

s1

' : '

c1

'); + } +}); diff --git a/packages/svelte/tests/runtime-runes/samples/async-props-id/main.svelte b/packages/svelte/tests/runtime-runes/samples/async-props-id/main.svelte new file mode 100644 index 000000000000..973d6855a619 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/async-props-id/main.svelte @@ -0,0 +1,6 @@ + + +

{id}