Skip to content

fix: avoid closing notice when duration changes to non-positive - #421

Merged
yoyo837 merged 1 commit into
react-component:masterfrom
mokshupadhyay:fix/duration-zero-auto-close
Dec 2, 2026
Merged

yoyo837 merged 1 commit into
react-component:masterfrom
mokshupadhyay:fix/duration-zero-auto-close

Conversation

@mokshupadhyay

@mokshupadhyay mokshupadhyay commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

When a notice that is already showing is updated with duration: 0 (or false / null) to make it persistent, it was still closed. useNoticeTimer reacts to a duration change by resetting its state and calling setWalking(durationMs > 0), but setWalking only takes effect on the next render. In that render walking is still true, so the timer effect runs with a non-positive duration and fires onClose.

Two small changes in src/hooks/useNoticeTimer.ts:

  • the timer effect now returns early when durationMs <= 0, so it never starts for a persistent notice;
  • the reset effect also clears lastRafTimeRef, so going from 0 back to a positive duration starts a fresh timer instead of reusing a stale timestamp.

Before / after (new tests):

scenario before after
notice open with duration: 1, updated to duration: 0, 5 s pass onClose called 1 time not called, notice still in the DOM
hook: duration 1 then 0, false or null, 2 s pass onClose called not called
hook: 1 → 0 → 1 fails on the original closes after a fresh 1 s

Tests: vitest run passes (6 files, 65 tests); 5 of the new tests fail on the original source. eslint src/ reports 0 errors (5 warnings, same on the base branch); tsc --noEmit prints no errors. I did not run the docs examples.

Open PR #409 also edits useNoticeTimer.ts (restarting the timer on same-key updates); it is a different symptom, but it touches nearby lines, so I'm happy to rebase on whichever lands first.

Summary by CodeRabbit

  • 修复
    • 通知时长更新为 0、false 或 null 后,通知不会因计时而自动关闭,更新后的内容仍会显示。
    • 通知恢复为正时长后,倒计时会从恢复时重新开始。

@vercel

vercel Bot commented Dec 1, 2026

Copy link
Copy Markdown

@mokshupadhyay 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 Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

此变更调整通知时长变化时的计时器重置和进度更新条件,并新增测试,验证非正时长不会触发关闭,以及时长恢复为正数后重新计时。

Changes

通知计时器

Layer / File(s) Summary
时长更新与计时器验证
src/hooks/useNoticeTimer.ts, tests/useNoticeTimer.test.tsx, tests/index.test.tsx
时长变化时清空上次 RAF 时间戳。进度更新仅在计时器运行且时长大于零时执行。测试覆盖时长变为 0、false 或 null,恢复正时长后的重新计时,以及通知更新为 duration: 0 后仍保持打开。

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

Change: Bug fix

Suggested reviewers: zombiej

Merge Risk: Minimal · up to 5f97e

This change stops a notice from closing when its duration is updated to 0, false or null, and restarts timing cleanly when a positive duration returns. The change is small and covered by new tests, so merge risk is minimal.

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: avoid closing notice when duration changes to non-positive”准确描述了主要变更:当 durationMs 变为非正值时,通知不再被关闭。变更内容包括 useNoticeTimer.ts 中对非正时长提前返回、清空 lastRafTimeRef,以及新增针对该行为的测试。标题与变更集直接相关,且具体明确。
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

兔子轻敲计时钟,
零时长时钟声停。
内容更新仍清晰,
正数回来再启程。
轻跃收尾,通知安宁。

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: 24cce593-0e69-4325-8a8c-db60394dfe3c
Commits

Reviewing files that changed from the base of the PR and between dac07d8 and 5f97eaf.

Files selected for processing: 3

  • 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 Dec 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.21%. Comparing base (dac07d8) to head (5f97eaf).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #421   +/-   ##
=======================================
  Coverage   99.21%   99.21%           
=======================================
  Files          12       12           
  Lines         382      383    +1     
  Branches      103      103           
=======================================
+ Hits          379      380    +1     
  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 merged commit 8e4f422 into react-component:master Dec 2, 2026
10 of 11 checks passed
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