-
|
Hi, I was working a project and encounter some issue with each block when iterating through Code (simplified example): <script>
import {SvelteSet} from 'svelte/reactivity';
let index = $state(0);
let initial = $state([0, 1])
const items = $derived(new SvelteSet(initial));
function handle() {
index = (index + 1) % 2;
items.clear();
const limit = index === 0 ? 2 : 1
for (let i = 0; i < limit; i++) {
items.add(i);
}
}
</script>
{#snippet list(value)}
<div hidden={index !== value}>
<p>Page: {index}</p>
{#each items.values() as v (v)}
{v}
<br />
{/each}
</div>
{/snippet}
<button onclick={handle}>switch page</button>
{@render list(0)}
{@render list(1)}What I expect the above to do is when the switch page button is clicked, the list should be updated (2 items -> 1 item -> 2 items ...). This works as expected if I visit this page directly. Yet, if I navigate to another page of this app and come back, the list remains with 2 items when I click the button. May I know why is that? Did I make some mistake? I am using SvelteKit |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
I figured it out, apparently experimental async is the culprit, removing this option resolves the problem |
Beta Was this translation helpful? Give feedback.
I figured it out, apparently experimental async is the culprit, removing this option resolves the problem