Skip to content

fix(Toast): a toast raised while the window is in the background starts with its timer paused - #9615

Merged
cixzhang merged 4 commits into
mainfrom
fix/toast-raised-while-blurred-held
Nov 3, 2026
Merged

cixzhang merged 4 commits into
mainfrom
fix/toast-raised-while-blurred-held

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #8969

User impact

This affects someone in another window or tab when an app raises an auto-hiding toast. Today the toast's timer starts at once, so it can disappear before they come back and they never see it. After this change, a toast raised while the window is in the background starts paused, and its timer runs once the window has focus again.

The other part of #8969, tracking each pause source separately (pointer, focus, gesture, window), is already on main. This closes the remaining gap that Toast FR2 names.

Authority

component:Toast FR2: "the timer pauses while … the window is blurred". Its implementation gap reads "a toast raised while the window is already blurred starts its timer". FR2 and AR3 require the timer to pause while the user can't read the toast (WCAG 2.2.1 Timing Adjustable).

Change

  • Toast.tsx: when the window-pause listeners attach and document.hasFocus() is false, the toast takes the window hold at once. The window's next focus event releases it, as it does after a blur.
  • Toast.spec.md: FR2's gap sentence becomes "A toast raised while the window is already blurred starts with its timer held". The matching Current-state impact bullet is removed, and the FR2 verification row names the new test.
  • Tests: ToastViewport.test.tsx and ToastViewport.modalHost.test.tsx now treat the test page as a focused window. jsdom reports no window focus until an element is focused, so without this, toasts in those files would start held.
  • Changeset: Core patch, [fix].

Verification

  • Unit, red first: "starts its auto-hide timer held until the window regains focus" fails on main and passes here. The Toast suites pass (110 tests), as do the other suites that raise toasts. Lint, type check and check-knowledge are clean.

  • Real Chromium 154 (2 s toast; "background" means another tab is in front, so document.hasFocus() is false):

    Case main This PR
    Window focused: toasts after 4.3 s 0 0
    Window in background: toasts after 4.3 s 0 (expired unseen) 1 (held)
    The user returns: toasts 3.5 s later 0 0 (resumed, then hid)

@vercel

vercel Bot commented Nov 2, 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 Nov 3, 2026 3:42am UTC

Request Review

@astracat-bot

astracat-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 3, 2026, 3:43 AM UTC

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

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 2250641

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
Toast · Storybook 59.4 kB (+10 B) · 10.1 kB CSS (0) 1,518 (+3) ✓ · ✓ · ✓
LayerProvider 62.7 kB (+8 B) · 10.5 kB CSS (0) — — · — · —

Package size: @astryxdesign/core 6.00 MB packed (+165 B); no new dependencies.

Touched components checked; add ci:run-visual, ci:run-a11y or ci:run-rtl to run the full suites.


Generated by PR Enrichment workflow | View full report

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

The fix itself looks right: a toast raised while the window has no focus now starts held, the new test fails on main and passes here, and a real-browser run shows the toast surviving the background and hiding after focus returns. One change is needed before this lands: the record's at-a-glance row at line 53 of docs/specs/components/Toast/Toast.spec.md still says "Nineteen implementation gaps", but this pull request removes one of them, so it should read "Eighteen". Optionally, add a changeset sentence that jsdom reports no document focus until an element is focused, so consumer tests that assert auto-hide now need to focus an element or mock document.hasFocus, as this pull request's own test files do.

[Automated review]

Comment on lines +299 to +300
// A toast raised while the window is already blurred gets no blur event,
// so it starts held, and the window's next focus resumes it.

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.

Non-blocking: this sentence carries three topics. A shorter form with one fact per sentence: A window that is already blurred fires no blur event. Start the toast held. The next window focus resumes it.

@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: a toast raised while the window has no focus now starts held, the new test fails on main and passes here, and the record's gap count now reads "Eighteen". Two optional touches: shorten the new comment in Toast.tsx to its one quirk ("A window that is already blurred fires no blur event."), and consider a changeset sentence that consumer jsdom tests asserting auto-hide now need to focus an element or mock document.hasFocus. The repository's spec gate still waits for an engineering owner's /approve-spec.

[Automated review]

@cixzhang
cixzhang marked this pull request as ready for review November 2, 2026 20:57
@cixzhang

cixzhang commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 8878b7f

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 2, 2026
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 3, 2026
@cixzhang

cixzhang commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 002098a

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 3, 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.

This looks ready: a toast raised while the window has no focus now starts held, the new test fails on main and passes here, and the record edit closes FR2's gap with an engineering owner's approval at this head.

Before it can merge, docs/specs/components/Toast/Toast.spec.md conflicts with main in the verification map, because main changed the FR12 row to "modal and scrimless drawers" and this branch re-pads the whole table: keep that wording when resolving, and the new head needs /approve-spec again. Optionally, shorten the new comment in Toast.tsx to its one quirk ("A window that is already blurred fires no blur event.") and add a changeset sentence that consumer jsdom tests asserting auto-hide now need to focus an element or mock document.hasFocus.

[Automated review]

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

cixzhang commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 2250641

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 3, 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.

This looks ready to merge: a toast raised while the window has no focus now starts with its auto-hide timer held, the new test fails on main and passes here, and the record edit closes FR2's implementation gap with an engineering owner's approval at this head.

Two optional touches:

  • Shorten the new comment in Toast.tsx to its one quirk: "A window that is already blurred fires no blur event."
  • Consider a changeset sentence that consumer jsdom tests asserting auto-hide now need a focused element or a document.hasFocus mock, since jsdom reports no document focus until an element is focused.

[Automated review]

@cixzhang
cixzhang merged commit 2de3888 into main Nov 3, 2026
95 of 98 checks passed
@github-actions
github-actions Bot deleted the fix/toast-raised-while-blurred-held branch November 3, 2026 06:05

This branch was successfully deployed

1 active deployment
Preview — 2250641a Deployed Nov 3, 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.

[Bug] Toast: the auto-hide pause is one flag, so a toast can hide while focus is inside it

1 participant