Fix hand re-animating on every turn #14
Loading…
Reference in a new issue
No description provided.
Delete branch "hand-deal-anim-fix"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The cards in the hand animated away and back (flew in from above with a stagger) every time it became my turn to play. Confusing and unnecessary — the cards should only animate when they are dealt.
Root cause
The
deal-inanimation is applied via thehand-card-animclass, which was gated onmyTurn:So every time
myTurnflipped false→true, React re-added the class to the already-mounted card elements, re-running thedeal-inkeyframe animation on the whole hand. It re-triggered on every one of my turns within a round.Fix
Gate the animation on a
dealtwindow instead ofmyTurn:dealtstate is set true for a brief period (DEAL_ANIM_MS = 1200ms— the longest stagger of 10 cards × 60ms plus the 400ms flight, with slack) after each fresh deal, i.e. whendealKeybumps, then removed.useLayoutEffectso the class is present before the first paint of the new cards (no flash of un-animated cards).keyincludesdealKey), so the animation runs exactly once per deal.Why the class is removed after the window (rather than left applied): the per-card stagger delay is a CSS variable (
--deal-i) that changes whenever the hand is sorted or dragged. I verified in the browser that changing the delay of an applieddeal-inanimation re-runs it (the opacity dips back toward thefromstate and recovers). So a lingering class would re-trigger the deal animation on Sort. With the class removed after the window, sorting only slides the cards to their new positions via the existing dnd-kit transition — the natural "sort" animation.Verified (real browser, Playwright)
deal-inanimations runningTests
hand-card-animclass even when it is not the player's turn. Confirmed it fails under the oldmyTurngating (0 cards instead of 2) and passes with the fix.Note: the
bot pacingtest insession.test.tsis timing-sensitive and flakes occasionally under load; unrelated to this change (no game/session code touched).