fix(ToastProvider): dismiss stuck toasts in a background tab (DS-4709) - #448
fix(ToastProvider): dismiss stuck toasts in a background tab (DS-4709)#448KamilEmeleev wants to merge 2 commits into
Conversation
|
Visit the preview URL for this PR (updated for commit 046bb1e): https://react-koobiq-next--prs-448-xxnqo1xy.web.app (expires Tue, 11 Aug 2026 12:11:21 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: fc29847d4a9e5cb1adf458c76a9b681c76e2eeff |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthrough
ChangesToast queue timing and lifecycle
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant BrowserDocument
participant KbqToastQueue
participant Ticker
KbqToastQueue->>Ticker: start ticker
Ticker->>KbqToastQueue: process elapsed time
BrowserDocument->>KbqToastQueue: visibility becomes visible
KbqToastQueue->>Ticker: run immediate tick
Ticker->>KbqToastQueue: close eligible timed toasts
KbqToastQueue->>KbqToastQueue: invoke onClose after deletion
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/components/src/components/ToastProvider/KbqToastQueue.ts`:
- Around line 217-231: Make clear() callback-safe by snapshotting and detaching
the existing queue before invoking any onClose callbacks, then process only the
detached toasts so callbacks cannot reprocess them. Preserve toasts added
through add() during callbacks in the live queue, and add a regression test
covering an onClose handler that calls add().
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: cb372fdc-f771-4da1-952b-6ae0404b27d1
📒 Files selected for processing (2)
packages/components/src/components/ToastProvider/KbqToastQueue.test.tspackages/components/src/components/ToastProvider/KbqToastQueue.ts
There was a problem hiding this comment.
Pull request overview
Fixes ToastProvider/ToastQueue auto-dismiss behavior when the browser tab is backgrounded and timer ticks are heavily throttled, ensuring expired toasts are dismissed promptly (and in the correct order) once execution resumes.
Changes:
- Added more robust time accounting in
ToastQueue(per-toastaddedAt,expiredAt, pause/resume adjustments) to handle delayed ticks and maintain close spacing. - Added a
visibilitychangelistener to force an immediate catch-up tick when the tab becomes visible again. - Expanded
ToastQueueunit tests to cover background-tab throttling, visibility resume, pause/resume interactions, and clock skew scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/components/src/components/ToastProvider/KbqToastQueue.ts | Updates the queue/ticker logic to correctly catch up on throttled ticks and visibility changes while preserving FIFO close order and close spacing. |
| packages/components/src/components/ToastProvider/KbqToastQueue.test.ts | Adds targeted tests for delayed ticks, visibility catch-up, pause/resume timing, and related edge cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // a toast queued mid-tick has only lived through part of it, | ||
| // and a system clock moved backwards must not add time back | ||
| const step = Math.max(0, Math.min(elapsed, now - (toast.addedAt ?? now))); |
Summary by CodeRabbit