Untrack all dispatch operations
Closed this issue · 1 comments
The read of selectedState
here can end up tracked in a reactive context like an effect
, if a dispatch is made inside of that context. This happens because a dispatch causes subscribers to run synchronously to receive the newly reduced state, and selectedState
is read inside a subscriber.
There are 2 possible fixes here:
-
For good reactive hygiene, ideally the whole
dispatch()
operation should be untracked. Nothing downstream ofdispatch()
makes sense to track if invoked from a reactive context. -
In addition to 1,
linkedSignal
supports equality directly so the read ofselectedState
in order to invoke the equality function is actually not necessary. Instead, the equality operation can be delegated tolinkedSignal
.
This is causing issues in a minimal repro I made here:
https://stackblitz.com/edit/stackblitz-starters-3iluayah?file=src%2Fmain.ts