Skip to content

fix(dice): clear roll interval on unmount (setState-after-unmount leak)#173

Merged
TortoiseWolfe merged 1 commit into
mainfrom
fix/dice-interval-leak
Jul 4, 2026
Merged

fix(dice): clear roll interval on unmount (setState-after-unmount leak)#173
TortoiseWolfe merged 1 commit into
mainfrom
fix/dice-interval-leak

Conversation

@TortoiseWolfe

Copy link
Copy Markdown
Owner

Root-caused from a CI flake

Dice.roll() starts a setInterval that fires setState every 100ms for 1s, with no cleanup. A Dice component unmounted mid-roll keeps calling setValue/setIsRolling on a dead component — a React "update on an unmounted component" leak.

It surfaced as a nondeterministic coverage-teardown crash: the Test (20.x) job exits 1 after printing "Tests 3614 passed", with a stack ending at Dice.tsx:25 inside a Timeout._onTimeout during React's dispatchSetState. Timing-dependent, so it passed on recent main commits and flaked on an unrelated PR (#172).

Fix

  • Track the interval in a useRef, clear it on unmount via useEffect cleanup.
  • Clear any in-flight roll before starting a new one (rapid re-click safety).

Dice tests 14/14, type-check clean. Small, isolated, kept out of the #168 monitor PR it flaked on.

🤖 Generated with Claude Code

… leak)

Dice.roll() started a setInterval that fires setState every 100ms for 1s
with no cleanup. A component unmounted mid-roll kept updating a dead
component — a React "update on unmounted component" leak that surfaced as a
nondeterministic coverage-teardown crash in CI (exit 1 after all tests
pass; caught on the #168 run, unrelated to that change).

Track the interval in a ref, clear it on unmount via useEffect, and clear
any in-flight roll before starting a new one. Dice tests 14/14, type-check
clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@TortoiseWolfe TortoiseWolfe merged commit ab09b36 into main Jul 4, 2026
18 checks passed
@TortoiseWolfe TortoiseWolfe deleted the fix/dice-interval-leak branch July 4, 2026 18:09
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.

2 participants