mirror of https://github.com/sveltejs/svelte
fix: correctly calculate `@const` blockers (#18039)
Move the calculation of blockers into the analysis phase and then only push the right thunks in the transform phase - similar to how we already do it with top level `$.run` Fixes #18024 The solution is a tiny bit brittle (not much more than the top level one we already have) and I tried to make it a bit more robust but ended up in a rabbit hole in #18032 - we can revisit that solution once all the old stuff is gone. Until then this is the most pragmatic/non-invasive change. --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/17666/merge
parent
7be1a0247f
commit
3937ec03bd
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: correctly calculate `@const` blockers
|
||||
@ -0,0 +1,9 @@
|
||||
import { tick } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async test({ assert, target }) {
|
||||
await tick();
|
||||
assert.htmlEqual(target.innerHTML, '<p>data</p>');
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,16 @@
|
||||
<script>
|
||||
let d = $derived(await Promise.resolve({ data: "data", hasData: true }));
|
||||
let showFetchCta = $derived(d.hasData)
|
||||
</script>
|
||||
|
||||
{#if d}
|
||||
{@const {data, hasData} = d}
|
||||
|
||||
{#if hasData}
|
||||
<p>{data}</p>
|
||||
{:else if showFetchCta}
|
||||
<p>Fetch now</p>
|
||||
{:else}
|
||||
<p>No data</p>
|
||||
{/if}
|
||||
{/if}
|
||||
Loading…
Reference in new issue