Skip to content

Commit 947494e

Browse files
committed
Fix for reactivity issue in TagSet constructor, but the next Svelte release should fix this anyway sveltejs/svelte#15553
1 parent 5e7e016 commit 947494e

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/lib/types.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { SvelteSet } from "svelte/reactivity";
2+
import { untrack } from "svelte";
23

34
export type Range = { min: number; max: number };
45

@@ -41,9 +42,14 @@ export type AutocompleteTag = {
4142
export class TagSet extends SvelteSet<string> {
4243
constructor(private autocomplete: AutocompleteTag[], tags: Set<string> = new Set()) {
4344
super(tags);
44-
for (const tag of this) {
45-
this.removeImplied(tag);
46-
}
45+
// Svelte tracks changes inside a constructor,
46+
// so assigning TagSet to a state would cause an infinite loop if this weren't wrapped with `untrack`.
47+
// This should be fixed in a newer version of Svelte https://github.com/sveltejs/svelte/pull/15553
48+
untrack(() => {
49+
for (const tag of this) {
50+
this.removeImplied(tag);
51+
}
52+
});
4753
}
4854

4955
add(tag: string) {

0 commit comments

Comments
 (0)