Skip to content

fix(web): move side effects out of state updater functions - #26

Merged
PunGrumpy merged 1 commit into
mainfrom
motion/06-pure-state-updaters
Aug 7, 2026
Merged

fix(web): move side effects out of state updater functions#26
PunGrumpy merged 1 commit into
mainfrom
motion/06-pure-state-updaters

Conversation

@PunGrumpy

@PunGrumpy PunGrumpy commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Problem

react-doctor scored the app 59/100: two no-impure-state-updater errors and eight no-side-effect-in-state-updater-function warnings, all in hooks/use-optimizer.ts.

Root Cause

React state updaters must be pure — under StrictMode they run twice, doubling any side effect inside them. patchOptions 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 (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

@vercel

vercel Bot commented Aug 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pigo Ready Ready Preview Aug 7, 2026 4:58pm
pigo-api Ready Ready Preview Aug 7, 2026 4:58pm

@vercel
vercel Bot temporarily deployed to Preview – pigo-api August 7, 2026 16:48 Inactive
@changeset-bot

changeset-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 34d5cab

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit 34d5cab.

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
PunGrumpy force-pushed the motion/06-pure-state-updaters branch from 2aa3abc to 34d5cab Compare August 7, 2026 16:57
@PunGrumpy
PunGrumpy merged commit 53cbb33 into main Aug 7, 2026
11 of 14 checks passed
@PunGrumpy
PunGrumpy deleted the motion/06-pure-state-updaters branch August 7, 2026 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant