Skip to content

fix: reset duration when updating notices - #409

Open
nrps9909 wants to merge 2 commits into
react-component:masterfrom
nrps9909:codex/reset-updated-duration
Open

nrps9909 wants to merge 2 commits into
react-component:masterfrom
nrps9909:codex/reset-updated-duration

Conversation

@nrps9909

@nrps9909 nrps9909 commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • restart a notice auto-close timer when the same key is updated
  • reuse the existing times update counter without resuming a paused notice
  • add a regression test that verifies the updated notice receives its full duration

Problem

Notifications.open increments times when an existing key is updated, but Notification did not pass that value to its timer. When a one-second notice was updated after 800 ms with the same one-second duration, it still closed about 200 ms later instead of remaining visible for another full second.

Validation

  • vitest run --maxWorkers=1 (3 files, 53 tests)
  • tsc --noEmit
  • father build (ESM, CJS, declarations)
  • Prettier and git diff --check
  • ESLint on the changed source files

I also checked the current open issues and PRs. The timer-related open PRs cover maximum timeout clamping, hover resume behavior, page blur, or progress styling; none resets the same-key update timer.

Summary by CodeRabbit

  • 新功能

    • 通知新增可选的计时次数配置。
    • 更新相同标识的通知后,自动关闭计时会重新开始。
  • 错误修复

    • 修复通知内容更新后,自动关闭计时未正确重置的问题。
  • 测试

    • 增加通知更新后计时重置的测试覆盖。

@vercel

vercel Bot commented Aug 28, 2026

Copy link
Copy Markdown

@nrps9909 is attempting to deploy a commit to the afc163's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Notification 将 times 传递给 useNoticeTimer。当 times 或更新回调变化时,计时器重置经过时间,并将进度更新为 0。新增测试覆盖相同 key 的通知更新和计时器参数签名变更。

Changes

通知计时器重置

Layer / File(s) Summary
计时器参数与组件接入
src/Notification.tsx, src/hooks/useNoticeTimer.ts
Notification 解构可选的 times 属性,并将其传递给新增该参数的 useNoticeTimer。
计时重置与验证
src/hooks/useNoticeTimer.ts, tests/index.test.tsx, tests/useNoticeTimer.test.tsx
当 times 或 onEventUpdate 变化时,计时器重置经过时间和动画帧起始时间,并报告进度 0。测试覆盖相同 key 的通知更新,以及更新后的 Hook 参数签名。

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

Suggested reviewers: zombiej, yoyo837, mokshupadhyay

Merge Risk: Minimal · up to 5dc2c

Updating a notice with the same key now restarts its auto-close timer, so it gets its full duration. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题“fix: reset duration when updating notices”与变更内容一致。变更让同 key 的通知更新时重置自动关闭计时器:Notification 将 times 传入 useNoticeTimer,计时器在 times 变化时从头计时。新增的测试验证更新后的通知会保留完整时长。标题准确描述了主要变更。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

小兔把 times 传给计时器,
通知更新,计时重新开始。
进度归零,帧时间也更新,
新内容按新的时长显示。
测试确认通知随后关闭。

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2df0b45c-0c04-4a35-bf39-5885ac5b8c0c
Commits

Reviewing files that changed from the base of the PR and between 881a0f9 and 5dc2c26.

Files selected for processing: 4

  • src/Notification.tsx
  • src/hooks/useNoticeTimer.ts
  • tests/index.test.tsx
  • tests/useNoticeTimer.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@codecov

codecov Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.22%. Comparing base (8e4f422) to head (5dc2c26).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #409      +/-   ##
==========================================
+ Coverage   99.21%   99.22%   +0.01%     
==========================================
  Files          12       12              
  Lines         383      389       +6     
  Branches      103      104       +1     
==========================================
+ Hits          380      386       +6     
  Misses          3        3              

☔ View full report in Codecov by Harness.
📢 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.

@yoyo837

yoyo837 commented Dec 2, 2026

Copy link
Copy Markdown
Member

Thanks for the fix! #421 has now landed. Could you rebase this PR onto the latest master and update all three calls in tests/useNoticeTimer.test.tsx to pass undefined as the second argument (times)?

Those calls still use the three-argument signature, so the combined changes fail TypeScript checking. For example, use useNoticeTimer(duration, undefined, onClose, onUpdate). Please rerun the type check and test suite after the update.

@yoyo837

yoyo837 commented Dec 2, 2026

Copy link
Copy Markdown
Member

One follow-up to my earlier comment: useNoticeTimer ships in the es/hooks and lib/hooks paths, so inserting times as the second argument breaks existing three-argument calls. Could we make times an optional fourth argument after onUpdate and keep the hook tests on the original three-argument signature?

This branch has not been deployed

No deployments
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.

2 participants