mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-07-16 23:24:55 -05:00
[PR #1913] [MERGED] fix(staffml): cancel StarGate's verify-delay timer on unmount #34642
Reference in New Issue
Block a user
Delete Branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/harvard-edge/cs249r_book/pull/1913
Author: @farhan523
Created: 6/28/2026
Status: ✅ Merged
Merged: 7/10/2026
Merged by: @profvjreddi
Base:
dev← Head:fix/stargate-clear-verify-timeout📝 Commits (1)
91fe269fix(staffml): cancel StarGate's verify-delay timer on unmount📊 Changes
2 files changed (+92 additions, -2 deletions)
View changed files
➕
interviews/staffml/src/__tests__/stargate-timer-cleanup.test.tsx(+74 -0)📝
interviews/staffml/src/components/StarGate.tsx(+18 -2)📄 Description
Summary
Both
handleStar("Star on GitHub") andhandleAlreadyStarred("I already starred") firedsetTimeout(onVerified, 1500)to let the user see the "Thank you" confirmation panel before the parent dismisses the gate. The returned timer id was never stored, so if the gate unmounted within that 1.5s window — parent route change, programmatic close, or anything that removesStarGatefrom the tree — the timer kept running andonVerifiedfired later on an unmounted parent.Today the only caller (
practice/page.tsx) treats a strayonVerifiedcall as a no-op (it just setsshowStarGate=falsewhich was already false), so this was a latent leak, not a visible bug. But the contract becomes accidentally correct rather than correct-by-design — a future caller whereonVerifiedmutates state on a stale tree would surface it immediately.Changes
verifyTimeoutRef(mirrors the focus-timer pattern already in the same file).useEffectthat clearsverifyTimeoutRef.currenton unmount.Test plan
npx vitest run→ 129/129 across 23 files passing (was 126; +3 new for unmount-after-Star, unmount-after-Already-starred, and still-mounted-fires-at-1.5s).npx tsc --noEmit→ clean.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.