Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
概述通知计时器的实现从基于超时机制重构为基于 RAF(requestAnimationFrame)驱动的增量时间累积方案,移除了 变更内容
代码审查工作量估算🎯 3 (中等) | ⏱️ ~20 分钟 可能相关的 PR
建议审核人
诗歌
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #386 +/- ##
==========================================
+ Coverage 98.96% 99.17% +0.21%
==========================================
Files 13 13
Lines 1352 1336 -16
Branches 183 178 -5
==========================================
- Hits 1338 1325 -13
+ Misses 14 11 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request refactors the useNoticeTimer hook to use useRef for managing timeout and animation frame identifiers, centralizing cleanup logic into a cleanupTimer callback. It also updates the onPause handler to reset the start timestamp and trigger cleanup, and adds a test case to verify that progress is correctly paused during hover events. Feedback was provided regarding missing dependencies in the onPause callback and the main useEffect hook to ensure hook stability and correctness.
| const onPause = React.useCallback(() => { | ||
| syncPassTime(); | ||
| startTimestampRef.current = null; | ||
| cleanupTimer(); | ||
| setWalking(false); | ||
| }, []); | ||
| }, [cleanupTimer]); |
There was a problem hiding this comment.
The onPause callback uses syncPassTime, but it is missing from the dependency array. If syncPassTime is made stable (as suggested), it should be added here to satisfy the linter and ensure correctness.
| const onPause = React.useCallback(() => { | |
| syncPassTime(); | |
| startTimestampRef.current = null; | |
| cleanupTimer(); | |
| setWalking(false); | |
| }, []); | |
| }, [cleanupTimer]); | |
| const onPause = React.useCallback(() => { | |
| syncPassTime(); | |
| startTimestampRef.current = null; | |
| cleanupTimer(); | |
| setWalking(false); | |
| }, [cleanupTimer, syncPassTime]); |
| }; | ||
| }, [durationMs, walking]); | ||
| return cleanupTimer; | ||
| }, [cleanupTimer, durationMs, onEventClose, onEventUpdate, trackProgress, walking]); |
There was a problem hiding this comment.
The useEffect hook uses syncPassTime (at line 67 and inside the step function), but it is missing from the dependency array. It should be added to ensure the effect correctly tracks its dependencies.
| }, [cleanupTimer, durationMs, onEventClose, onEventUpdate, trackProgress, walking]); | |
| }, [cleanupTimer, durationMs, onEventClose, onEventUpdate, syncPassTime, trackProgress, walking]); |
2a699df to
5df49ad
Compare
5df49ad to
63ee92e
Compare
63ee92e to
8103b9f
Compare
8103b9f to
2e7ed1a
Compare
2e7ed1a to
55ff4c9
Compare
55ff4c9 to
e503574
Compare
Summary
trackProgresstimer path and drive notice elapsed time from one raf-based timer.lastRafTimeRefas the per-frame timestamp whilepassTimeRefremains the elapsed-time accumulator, so hover pause stops elapsed time from advancing until resume resets the frame timestamp.showProgresssetup from the hover timing test.Root Cause
The previous timestamp bookkeeping could keep syncing elapsed time from the old active timestamp after hover pause, making a long hover consume the remaining duration.
Validation
npm test -- --runnpm run lint(passes with existing hook dependency warnings)Summary by CodeRabbit
重构