Summary
client/src/hooks/useCountdown.ts drives the CountdownTimer component. setInterval-based countdowns accumulate drift over time (~1 second per hour). For raffles ending in hours, this can show incorrect end times.
What to do
- Replace the
setInterval approach with a requestAnimationFrame loop that re-syncs to Date.now() on every frame.
- Alternatively, use
performance.now() as a stable reference and re-compute remaining time on each tick.
- Write a unit test using
vi.useFakeTimers() that advances time by 1 hour and asserts the displayed remaining time is accurate to within 1 second.
Acceptance criteria
- After advancing fake timers by 1 hour, the countdown display is within 1 second of the correct value.
- The component re-calculates from the
endTime on every tick rather than decrementing a counter.
Summary
client/src/hooks/useCountdown.tsdrives the CountdownTimer component.setInterval-based countdowns accumulate drift over time (~1 second per hour). For raffles ending in hours, this can show incorrect end times.What to do
setIntervalapproach with arequestAnimationFrameloop that re-syncs toDate.now()on every frame.performance.now()as a stable reference and re-compute remaining time on each tick.vi.useFakeTimers()that advances time by 1 hour and asserts the displayed remaining time is accurate to within 1 second.Acceptance criteria
endTimeon every tick rather than decrementing a counter.