-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Closed as not planned
Description
Describe the bug
Behaviors of 1 and 3 are inconsistent.
- Works without warning:
<script lang="ts">
import { SvelteSet } from 'svelte/reactivity';
let ids = new SvelteSet([1]);
</script>
{#each ids as id (id)}{id}{/each}
<!-- Pressing this will render 2 above -->
<button type="button" onclick={() => (ids = new SvelteSet([2]))}>
Update IDs
</button>
- Breaks. Pressing the button does not render
2
<script lang="ts">
import { SvelteSet } from 'svelte/reactivity';
// `ids` is updated, but is not declared with `$state(...)`.
let ids = new SvelteSet([1]);
const count = $derived(ids.size); // added
</script>
{#each ids as id (id)}{id}{/each}
<button type="button" onclick={() => (ids = new SvelteSet([2]))}>
Update IDs
</button>
- Works, but results in ESLint error:
<script lang="ts">
import { SvelteSet } from 'svelte/reactivity';
// SvelteSet is already reactive, $state wrapping is unnecessary.
let ids = $state(new SvelteSet([1]));
const count = $derived(ids.size); // added
</script>
{#each ids as id (id)}{id}{/each}
<button type="button" onclick={() => (ids = new SvelteSet([2]))}>
Update IDs
</button>
Reproduction
https://svelte.dev/playground/31fb8c5a3285467ebbed95ec40ce7d30?version=5.36.6
Severity
annoyance
Metadata
Metadata
Assignees
Labels
No labels