I sometimes get a cycle detection error when there is no cycle. There are diamonds in the graph but no cycles, and statement order in the source code matters, i.e. sometimes re-ordering the reactive statements in the code doesn't give a cycle error.
To Reproduce
https://svelte.dev/repl/c58d52de222546a0a743fe6fb158568c?version=3.9.1
Expected behavior
No cycle detection bug error for any variant of this problem
Severity
I cannot use Svelte when it is giving spurious and incorrect error messages.
To make this easy to follow, I renamed variables so that every variable only refers to variables before it in the alphabet, which makes it easy to see the lack of cycles.
I simplified your example even more:
<script>
$: c = a + b;
$: a = 10;
$: b = a;
// putting the reactive declarations $: c = a + b; here won't generate a cyclical dependency error
</script>
See REPL.
To make it easier to find/fix cycle dependency problem, here is a lesson learned from past (totally unrelated to Svelte) situations:
Ban the use of error messages that just say "Cyclical dependency detected" or which point out one bit of the cycle. Require that any such message describe the whole cycle. This tends to yield much more insight when it goes awry "in the field".
Yes, please describe the whole cycle. This was a pain to debug and reduce because I had no idea what it was talking about in the beginning.
released 3.10 with the fix, thank you!
Most helpful comment
To make it easier to find/fix cycle dependency problem, here is a lesson learned from past (totally unrelated to Svelte) situations:
Ban the use of error messages that just say "Cyclical dependency detected" or which point out one bit of the cycle. Require that any such message describe the whole cycle. This tends to yield much more insight when it goes awry "in the field".