SvelteSet infinite loop #14123
SvelteSet infinite loop
#14123
-
Hi, I'm a newbie to svelte and I was trying out this piece of code. Whenever there is an update to a SvelteSet inside an effect block it triggers an infinite update, any idea if this is the expected behavior or any explanation on this behavior would be helpful <script>
import { SvelteSet } from 'svelte/reactivity';
let x = new SvelteSet();
$effect(() => {
let y = new SvelteSet();
y.add(1); // seems to trigger the update
if (y.symmetricDifference(x).size != 0) {
console.log("diff found");
// x = y;
}
})
</script> |
Beta Was this translation helpful? Give feedback.
Answered by
brunnerh
Nov 2, 2024
Replies: 1 comment
-
I suspect that this is expected, you read and write to a reactive object in the same Here would be a minimal example causing the same: <script>
$effect(() => {
let v = $state(0);
v = v + 1;
})
</script> Would recommend not unnecessarily creating stateful objects in the |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
megashrieks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I suspect that this is expected, you read and write to a reactive object in the same
$effect
, causing it to trigger again.Here would be a minimal example causing the same:
Would recommend not unnecessarily creating stateful objects in the
$effect
and/or untracking the read operations.