mirror of https://github.com/sveltejs/svelte
Implemented by reusing the `async_body` function inside `Fragment.js`. Also removes the ability to reference a `{@const ...}` of an implicit child inside a boundary pending/failed snippet: - existing duplication of consts can have unintended side effects, e.g. async consts would unexpectedly called multiple times - what if a const is the reason for the failure of a boundary, but is then referenced in the failed snippet? - what if an async const is referenced in a pending snippet? deadlock - inconsistent with how it behaves for components where this already does not work Implemented via the experimental flag so the behavior change only applies there as this is a breaking change strictly speaking. Also added a compiler error for this. closes #16462pull/16643/head
parent
1dcced59e7
commit
d41d82189f
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: allow async `{@const}` in more places
|
@ -0,0 +1,10 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async: true,
|
||||
error: {
|
||||
code: 'const_tag_invalid_reference',
|
||||
message: 'The `{@const foo = ...}` declaration is not available in this snippet ',
|
||||
position: [376, 379]
|
||||
}
|
||||
});
|
@ -0,0 +1,32 @@
|
||||
<svelte:options runes />
|
||||
|
||||
<!-- ok -->
|
||||
<svelte:boundary>
|
||||
{@const foo = 'bar'}
|
||||
|
||||
{#snippet other()}
|
||||
{foo}
|
||||
{/snippet}
|
||||
|
||||
{foo}
|
||||
|
||||
<svelte:boundary>
|
||||
{#snippet failed()}
|
||||
{foo}
|
||||
{/snippet}
|
||||
</svelte:boundary>
|
||||
|
||||
{#snippet failed()}
|
||||
{@const foo = 'bar'}
|
||||
{foo}
|
||||
{/snippet}
|
||||
</svelte:boundary>
|
||||
|
||||
<!-- error -->
|
||||
<svelte:boundary>
|
||||
{@const foo = 'bar'}
|
||||
|
||||
{#snippet failed()}
|
||||
{foo}
|
||||
{/snippet}
|
||||
</svelte:boundary>
|
@ -0,0 +1,10 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async: true,
|
||||
error: {
|
||||
code: 'const_tag_invalid_reference',
|
||||
message: 'The `{@const foo = ...}` declaration is not available in this snippet ',
|
||||
position: [298, 301]
|
||||
}
|
||||
});
|
@ -0,0 +1,27 @@
|
||||
<svelte:options runes />
|
||||
|
||||
<!-- ok -->
|
||||
<Component>
|
||||
{@const foo = 'bar'}
|
||||
{foo}
|
||||
|
||||
<Component>
|
||||
{#snippet prop()}
|
||||
{foo}
|
||||
{/snippet}
|
||||
</Component>
|
||||
|
||||
{#snippet prop()}
|
||||
{@const foo = 'bar'}
|
||||
{foo}
|
||||
{/snippet}
|
||||
</Component>
|
||||
|
||||
<!-- error -->
|
||||
<Component>
|
||||
{@const foo = 'bar'}
|
||||
|
||||
{#snippet prop()}
|
||||
{foo}
|
||||
{/snippet}
|
||||
</Component>
|
@ -0,0 +1,18 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
skip_async: true,
|
||||
html: '<button></button><p>2</p>',
|
||||
mode: ['client'],
|
||||
test({ target, assert }) {
|
||||
const btn = target.querySelector('button');
|
||||
const p = target.querySelector('p');
|
||||
|
||||
flushSync(() => {
|
||||
btn?.click();
|
||||
});
|
||||
|
||||
assert.equal(p?.innerHTML, '4');
|
||||
}
|
||||
});
|
@ -0,0 +1,14 @@
|
||||
<script>
|
||||
import FlakyComponent from "./FlakyComponent.svelte";
|
||||
let test=$state(1);
|
||||
</script>
|
||||
|
||||
<button onclick={()=>test++}></button>
|
||||
|
||||
<svelte:boundary>
|
||||
{@const double = test * 2}
|
||||
{#snippet failed()}
|
||||
<p>{double}</p>
|
||||
{/snippet}
|
||||
<FlakyComponent />
|
||||
</svelte:boundary>
|
@ -1,14 +1,10 @@
|
||||
<script>
|
||||
import FlakyComponent from "./FlakyComponent.svelte";
|
||||
let test=$state(1);
|
||||
let count = $state(1);
|
||||
</script>
|
||||
|
||||
<button onclick={()=>test++}></button>
|
||||
<button onclick={()=>count++}>increment</button>
|
||||
|
||||
<svelte:boundary>
|
||||
{@const double = test * 2}
|
||||
{#snippet failed()}
|
||||
{@const double = count * 2}
|
||||
<p>{double}</p>
|
||||
{/snippet}
|
||||
<FlakyComponent />
|
||||
</svelte:boundary>
|
Loading…
Reference in new issue