AK0031
Signal set() called during computation
What happened
You called .set() on a signal while inside a computed() callback or during an effect's tracking phase. Writing to signals during computation can cause infinite re-evaluations.
How to fix
Move signal writes to event handlers, onMount(), or wrap them in batch() to defer the update.
Example
ts
// Bad — writing a signal inside computed()
const count = signal(0);
const doubled = computed(() => {
count.set(count() * 2); // writing during computation!
return count();
});
// Good — derive values without side effects
const count = signal(0);
const doubled = computed(() => count() * 2);
// Good — write signals in event handlers
function handleClick() {
batch(() => {
count.set(count() + 1);
});
}