fix(web): move side effects out of state updater functions - #26
Merged
Conversation
|
Contributor
|
React Doctor found no new issues. 🎉 Reviewed by React Doctor for commit |
PunGrumpy
force-pushed
the
motion/06-pure-state-updaters
branch
from
August 7, 2026 16:50
c4db1e1 to
2aa3abc
Compare
React state updaters must be pure — under StrictMode they run twice, so the side effects inside them fired twice. patchOptions revoked nothing but wrote optionsRef, scheduled timers/microtasks, and called other setters inside its setOptions updater; removeJob revoked object URLs and nested setSelectedId inside its setJobs updater; runJob revoked the prior result URL inside an updateJob updater. All side effects now run in the event-handler body before a pure state write, sourcing current values from jobsRef/optionsRef. Clears react-doctor no-impure-state-updater (2 errors) and no-side-effect-in-state-updater-function (8 warnings). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
PunGrumpy
force-pushed
the
motion/06-pure-state-updaters
branch
from
August 7, 2026 16:57
2aa3abc to
34d5cab
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
react-doctor scored the app 59/100: two
no-impure-state-updatererrors and eightno-side-effect-in-state-updater-functionwarnings, all inhooks/use-optimizer.ts.Root Cause
React state updaters must be pure — under StrictMode they run twice, doubling any side effect inside them.
patchOptionswroteoptionsRef, scheduled timers/microtasks, and called other setters inside itssetOptionsupdater;removeJobrevoked object URLs and nestedsetSelectedIdinside itssetJobsupdater;runJobrevoked the prior result URL inside anupdateJobupdater (unflagged, same class of bug).Solution
All side effects now run in the event-handler body before a pure state write, sourcing current values from
jobsRef/optionsRef(which were already the synchronous source of truth). Behavior is unchanged; double-firing under StrictMode is gone.Result
Clears 2 errors + 8 warnings. All 43 web tests pass, typecheck clean.
🤖 Generated with Claude Code