Skip to content

[codex] fix hover pause timer#386

Merged
zombieJ merged 1 commit intomasterfrom
codex/fix-hover-pause-timer
Apr 28, 2026
Merged

[codex] fix hover pause timer#386
zombieJ merged 1 commit intomasterfrom
codex/fix-hover-pause-timer

Conversation

@zombieJ
Copy link
Copy Markdown
Member

@zombieJ zombieJ commented Apr 28, 2026

Summary

  • Remove the separate trackProgress timer path and drive notice elapsed time from one raf-based timer.
  • Keep lastRafTimeRef as the per-frame timestamp while passTimeRef remains the elapsed-time accumulator, so hover pause stops elapsed time from advancing until resume resets the frame timestamp.
  • Update timer tests to advance fake timers in raf-sized slices, and remove the extra showProgress setup 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 -- --run
  • npm run lint (passes with existing hook dependency warnings)

Summary by CodeRabbit

重构

  • 优化了通知系统的计时精度和算法,改进了进度跟踪机制
  • 增强了暂停和恢复功能的稳定性和准确性

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
notification Ready Ready Preview, Comment Apr 28, 2026 7:32am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 28, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 71441f88-5eee-4871-8f91-762b83d97202

📥 Commits

Reviewing files that changed from the base of the PR and between ce28148 and e503574.

📒 Files selected for processing (4)
  • src/Notification.tsx
  • src/hooks/useNoticeTimer.ts
  • tests/hooks.test.tsx
  • tests/index.test.tsx

概述

通知计时器的实现从基于超时机制重构为基于 RAF(requestAnimationFrame)驱动的增量时间累积方案,移除了 trackProgress 参数,简化了组件与钩子间的接口调用。相应测试用例更新以适配新的计时行为。

变更内容

衔接/文件(s) 总结
核心钩子重构
src/hooks/useNoticeTimer.ts, src/Notification.tsx
移除 trackProgress 参数;使用 lastRafTimeRef 替代 startTimestampRef 进行 RAF 驱动的增量时间追踪;效果重组使得时长变化时重置经过时间,监听 walking 状态切换启停 RAF 回调;完成逻辑完全集成至 RAF step() 流程,取消超时基础的最终更新。
测试套件更新
tests/hooks.test.tsx, tests/index.test.tsx
添加 step() 辅助函数以定量推进伪计时器(默认 16ms 步长),替换 vi.runAllTimers()vi.advanceTimersByTime() 调用;确保测试在特定时间点(如 500ms)断言中间行为而非穷尽所有计时器。

代码审查工作量估算

🎯 3 (中等) | ⏱️ ~20 分钟

可能相关的 PR

建议审核人

  • afc163

诗歌

🐰 RAF 之舞替时钟,✨
增量流转无停滞,
trackProgress 已烟消,
虚拟步进验真实,
计时器焕新生!⏱️

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-hover-pause-timer

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.17%. Comparing base (ce28148) to head (e503574).
⚠️ Report is 1 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/hooks/useNoticeTimer.ts Outdated
Comment on lines +45 to +50
const onPause = React.useCallback(() => {
syncPassTime();
startTimestampRef.current = null;
cleanupTimer();
setWalking(false);
}, []);
}, [cleanupTimer]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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]);

Comment thread src/hooks/useNoticeTimer.ts Outdated
};
}, [durationMs, walking]);
return cleanupTimer;
}, [cleanupTimer, durationMs, onEventClose, onEventUpdate, trackProgress, walking]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
}, [cleanupTimer, durationMs, onEventClose, onEventUpdate, trackProgress, walking]);
}, [cleanupTimer, durationMs, onEventClose, onEventUpdate, syncPassTime, trackProgress, walking]);

@zombieJ zombieJ force-pushed the codex/fix-hover-pause-timer branch from 55ff4c9 to e503574 Compare April 28, 2026 07:32
@zombieJ zombieJ marked this pull request as ready for review April 28, 2026 07:45
@zombieJ zombieJ merged commit 63d74d3 into master Apr 28, 2026
9 of 10 checks passed
@zombieJ zombieJ deleted the codex/fix-hover-pause-timer branch April 28, 2026 07:45
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.

1 participant