Repository navigation
fix(Toast): each auto-hide pause condition holds the timer on its own - #9016
Conversation
The pause was one flag, so the first condition to end (pointer leaving, focus leaving, window regaining focus) resumed the timer while another still held, and a toast could hide with focus on its action. Track pointer, focus, gesture and window holds separately; focus moving between the card's own controls keeps it held. Toast.spec.md FR2 and Current-state impact follow.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook Preview🧪 Sandbox PreviewModified ComponentsToast (@astryxdesign/core) · View in Storybook
Component Size
Sizes are gzip. Import counts the JavaScript the import loads eagerly; CSS counts the package stylesheet rules referenced by the modules it can load from its own package, lazily loaded ones included. Bundle Size SummaryGzip figures measure each package's entry file, not the code an import pulls in.
Accessibility AuditStatus: The accessibility audit did not run on this pull request. It runs after merges to Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
|
/approve-spec cae98f6 |
|
Posted by Cindy's agent on her behalf: the approval above covers a consistency edit to Toast FR2. It closes the recorded pause-source gap now that the code fixes it; the blurred-at-raise gap stays listed. |
|
AI review status for this pull request.
|
There was a problem hiding this comment.
This looks ready to approve: tracking each auto-hide pause condition separately restores component:Toast FR2, and the two new overlap tests fail without the fix and pass with it. Two small follow-ups before merging: trim the FR2 entry under "Read from source, with no focused test yet" in Toast.spec.md, since the new tests now cover pointer and focus pausing, and consider Refs #8969 instead of Fixes #8969, because the blurred-at-raise part of that issue is still open.
[Automated review]
There was a problem hiding this comment.
Changes requested: tracking each pause condition separately fixes both overlap cases from #8969, and the two new overlap tests fail without the fix and pass with it, but the focus hold can now outlive the control that holds focus. When a focused toast action unmounts (for example an Undo that replaces itself with "Undone"), React reports no blur to the card, so focus stays in the pause set and the toast never auto-hides after the pointer leaves or the window regains focus, where it used to hide; please drop the focus hold once focus is no longer inside the card and add a regression test with an action that unmounts itself while focused. The branch also needs a rebase onto main, where the Toast record's FR3 row changed, and a fresh /approve-spec for the new head.
[Automated review]
| if (next instanceof Node && event.currentTarget.contains(next)) { | ||
| return; | ||
| } | ||
| resumeTimer('focus'); |
There was a problem hiding this comment.
This is now the only path that releases the focus hold. When the focused control unmounts (an Undo that replaces itself, say), focus drops to the page body but React delivers no blur during that commit, so focus stays in the set and the toast never auto-hides, even after the pointer leaves or the window regains focus. Before, either of those events cleared the shared flag. Consider dropping focus whenever a hold ends and the card no longer contains document.activeElement, plus a test with an action that unmounts itself while focused.
A control that unmounts while focused fires no blur, so its focus hold stayed and the toast never auto-hid after the pointer left. When any hold ends, drop the focus hold if focus is no longer inside the card.
There was a problem hiding this comment.
This looks ready to approve: tracking each auto-hide pause condition on its own restores component:Toast FR2, and the new tests cover both overlap cases from #8969 plus a focused control that is removed. Before merging, please rebase onto main, where the Toast record's FR3 row changed right next to the FR2 row this pull request edits, keep main's FR3 text when you resolve the conflict, and have an engineering owner (the author may do this as one) comment /approve-spec <full head SHA> on the head that lands, since the earlier approval names an earlier commit.
[Automated review]
# Conflicts: # packages/core/src/Toast/Toast.spec.md
There was a problem hiding this comment.
This looks ready to approve: tracking each auto-hide pause condition on its own restores component:Toast FR2, and the new tests cover both overlap cases from #8969 plus a focused control that is removed, with main's FR3 row kept through the merge. Before merging, an engineering owner (the author can do this as one) needs to comment /approve-spec <full head SHA> on this head, since the existing approval names an earlier commit and the spec-owner-approval check is still pending.
[Automated review]
|
/approve-spec be9fced |
Refs #8969 (the auto-hide pause half; a toast raised while the window is already blurred stays open).
User impact
Someone reading a toast or about to use its action (Undo, Retry) can lose it mid-interaction. If they hover the toast and then Tab or click onto its action, moving the pointer away restarts the auto-hide timer even though focus is still on the action, and the toast hides under them. The same happens when the window regains focus while the pointer is over the toast. Keyboard and screen-reader users who reach a toast's action are hit hardest, because they can't easily get it back.
Problem and solution fit
The fix tracks each pause condition on its own. One ending resumes the timer only when no other still holds, and focus moving between the toast's own controls keeps it held.
Expected behavior and authority
component:Toast(current) FR2: the timer pauses while the pointer is over the card, focus is inside it, a touch or pen gesture is active, or the window is blurred. AR3: auto-hide pauses while the user reads or interacts. Its review checks reject "an auto-hide that runs while the user is reading or interacting", and its Current-state impact listed this exact gap ("The auto-hide pause is one flag"). This PR removes that gap from the record. The other half of the same bullet, a toast raised while the window is already blurred, stays listed: it needs a reliable window-focus signal at mount and is a separate change.Smallest restoration
Toast.tsx: the singleisPausedRefbecomes a set of pause sources (pointer,focus,gesture,window). The timer runs only when the set is empty; remaining-time accounting is unchanged (at least 1 s left on resume). The gesture hook gets source-specific callbacks; its own API is unchanged.Toast.spec.md: FR2 states the per-source pause; the closed gap leaves Current-state impact; the FR2 verification row names the new tests.Evidence
ToastViewport.test.tsx"keeps the timer paused while focus is inside after the pointer leaves", "…while the pointer is over it after the window regains focus", and "…while focus moves between controls inside the card".Writing rubric results
Scope
Testing
pnpm vitest run packages/core/src/Toast;pnpm -F @astryxdesign/core exec tsc --noEmit;pnpm check:knowledge. The behavior is timer and event ordering (no layout or pixels); the tests drive React's real mouse, focus and window events.