Skip to content

fix(Toast): each auto-hide pause condition holds the timer on its own - #9016

Merged
cixzhang merged 5 commits into
mainfrom
fix/toast-pause-sources
Oct 31, 2026
Merged

cixzhang merged 5 commits into
mainfrom
fix/toast-pause-sources

Conversation

@cixzhang

@cixzhang cixzhang commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Why does it hide? The auto-hide pause was one boolean shared by every pause condition: pointer over the card, focus inside it, a touch or pen gesture, the window blurred. Whichever condition ended first cleared it and restarted the timer.
  • Why does that harm the task? The toast disappears while the user is still reading it or operating it, so the action is lost.
  • Why does that matter? Toast exists to offer a short-lived, reachable action; one that can vanish under focus fails WCAG 2.2.1 Timing Adjustable and the component's own timing rule.

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 single isPausedRef becomes 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.
  • No public API, default, visual or DOM change.

Evidence

  • Reproduction before the change: the two new overlap tests fail on main (pointer leaves while focus is inside → hidden; window regains focus while the pointer is over → hidden).
  • Result after the change: all three new tests pass; the full Toast suite passes (93 tests).
  • Representative unchanged path: the existing window-blur pause, the new-toast-during-pause, swipe and dismissal tests pass unchanged.
  • Regression test: 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

  • R1 narration: FR2 and Current-state impact describe the system in the present tense.
  • R2 research: none.
  • R3 evidence: the verification row names tests, not pull requests.
  • R4 rejected alternatives: none added.
  • R5 change references: none.
  • R6 open questions: none.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

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.

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.
@vercel

vercel Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 30, 2026 10:29pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 30, 2026
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Oct 30, 2026
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

Modified Components

Toast (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Entry File (ESM) 304B 304B 0B
Lines of Code 1403 1463 -
Complexity Very High Very High (157) -

Component Size

Component Import before Import after Delta CSS before CSS after Delta
core/LayerProvider 65.0KB 65.2KB +180B 10.3KB 10.3KB 0B
core/Toast 61.5KB 61.7KB +203B 9.9KB 9.9KB 0B

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 Summary

Gzip figures measure each package's entry file, not the code an import pulls in.

Package Entry (ESM) Entry gzip before Entry gzip after Delta
@astryxdesign/core 4.9KB 1.2KB 1.2KB 0B
Package stylesheet Gzip before Gzip after Delta
@astryxdesign/core 35.6KB 35.6KB 0B

Accessibility Audit

Status: The accessibility audit did not run on this pull request. It runs after merges to main and before each release; pull requests that touch components run it with the ci:heavy-lanes label.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec cae98f6

@cixzhang

Copy link
Copy Markdown
Contributor Author

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.

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Oct 30, 2026
@astracat-bot

astracat-bot Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 30, 2026, 10:44 PM UTC

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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]

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Oct 30, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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]

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec be9fced

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Oct 30, 2026
@cixzhang
cixzhang marked this pull request as ready for review October 31, 2026 00:35
@cixzhang
cixzhang merged commit 743906f into main Oct 31, 2026
144 of 149 checks passed

This branch was successfully deployed

1 active deployment
Preview — be9fcedc Deployed Oct 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant