ensure async static props/attributes are awaited

pull/17120/head
Simon Holthausen 3 days ago
parent 24ed44c10f
commit 956e81bf5b

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: ensure async static props/attributes are awaited

@ -171,8 +171,6 @@ export function build_component(node, component_name, context) {
attribute.value,
context,
(value, metadata) => {
if (!metadata.has_state && !metadata.has_await) return value;
// When we have a non-simple computation, anything other than an Identifier or Member expression,
// then there's a good chance it needs to be memoized to avoid over-firing when read within the
// child component (e.g. `active={i === index}`)

@ -122,7 +122,7 @@ export function build_attribute_value(value, context, memoize = (value) => value
return {
value: memoize(expression, chunk.metadata.expression),
has_state: chunk.metadata.expression.has_state || chunk.metadata.expression.has_await
has_state: chunk.metadata.expression.has_state || chunk.metadata.expression.is_async()
};
}

@ -0,0 +1,5 @@
<script>
let { value } = $props();
</script>
{value}

@ -0,0 +1,11 @@
import { tick } from 'svelte';
import { test } from '../../test';
export default test({
mode: ['async-server', 'client', 'hydrate'],
ssrHtml: 'value <div class="value"></div>',
async test({ assert, target }) {
await tick();
assert.htmlEqual(target.innerHTML, 'value <div class="value"></div>');
}
});

@ -0,0 +1,10 @@
<script>
import Child from './Child.svelte';
await 1;
let value = 'value';
</script>
<Child {value} />
<div class={value}></div>
Loading…
Cancel
Save