Finding
Both createDerive (lines 247-254) and createSelect (lines 286-294) in src/index.ts have a !initialized branch in their getter functions. This branch duplicates computation logic from the effect and appears unreachable under normal usage — createEffect always runs the effect synchronously.
The branch is reachable when derive() or select() is called inside batch(), because batch defers effect creation. Without the lazy-init fallback, reading a derived value inside batch would return stale data.
The code is correct. The reason it exists is not documented.
Proposed fix
Add a brief comment above each !initialized branch explaining the batch-deferred edge case. Something like:
// When derive() is called inside batch(), effect creation is deferred.
// This fallback ensures the first read still returns the computed value.
No behavioral change needed.
Source: out/report-simplify.txt, Findings 3 + 4
Finding
Both
createDerive(lines 247-254) andcreateSelect(lines 286-294) insrc/index.tshave a!initializedbranch in their getter functions. This branch duplicates computation logic from the effect and appears unreachable under normal usage —createEffectalways runs the effect synchronously.The branch is reachable when
derive()orselect()is called insidebatch(), because batch defers effect creation. Without the lazy-init fallback, reading a derived value inside batch would return stale data.The code is correct. The reason it exists is not documented.
Proposed fix
Add a brief comment above each
!initializedbranch explaining the batch-deferred edge case. Something like:No behavioral change needed.
Source:
out/report-simplify.txt, Findings 3 + 4