Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: pause toast dismiss timers on hover/focus, add keyboard path to Undo (#8117)
[._.]/ Adam Eivy4edff853defd
diff --git a/client/src/components/KeyboardHelp.jsx b/client/src/components/KeyboardHelp.jsxindex e6346beb5a..b204346e90 100644--- a/client/src/components/KeyboardHelp.jsx+++ b/client/src/components/KeyboardHelp.jsx@@ -13,6 +13,7 @@ const SHORTCUT_SECTIONS = [{ keys: [`${modKey}+K`], description: 'Open command palette' },{ keys: ['?'], description: 'Show keyboard shortcuts' },{ keys: ['Esc'], description: 'Close overlays' },+ { keys: ['Alt+Shift+N'], description: 'Focus the newest notification' },],},{diff --git a/client/src/components/ui/Toast.jsx b/client/src/components/ui/Toast.jsxindex 254ee85f52..36ad1ac573 100644--- a/client/src/components/ui/Toast.jsx+++ b/client/src/components/ui/Toast.jsx@@ -13,6 +13,7 @@import { Loader2 } from 'lucide-react';import { useState, useEffect, useRef } from 'react';import { uuidv4 } from '../../lib/uuid.js';+import { isEditableTarget } from '../../lib/a11yKeyboard.js';let toasts = [];const listeners = new Set();@@ -97,7 +98,11 @@ function add(content, opts = {}, type = 'default') {: [...toasts, entry];notify();- if (duration !== Infinity) setTimeout(() => dismiss(id), duration);+ // The finite-duration dismiss timer used to be armed HERE, at creation, and+ // never touched again — so hovering or focusing a toast (the `held` state+ // below) could not pause it, and a keyboard user reaching for an Undo+ // button lost it mid-reach. It now lives in `ToastItem`'s own effect, which+ // can see `held` and pause/resume around it (#8117).return id;}@@ -124,6 +129,10 @@ const TYPE_CLASS = { success: 'text-port-success', error: 'text-port-error', loaexport function Toaster({ position = 'bottom-right', toastOptions = {} }) {const [items, setItems] = useState([]);+ const regionRef = useRef(null);+ // Where to send focus back on Escape — only set while focus is parked+ // inside the notification region via the Alt+Shift+N jump below.+ const returnFocusRef = useRef(null);useEffect(() => {const fn = ts => setItems(ts);@@ -131,6 +140,51 @@ export function Toaster({ position = 'bottom-right', toastOptions = {} }) {return () => listeners.delete(fn);}, []);+ // The keyboard path into the notification region (#8117): the Toaster is+ // mounted last in `main.jsx` so its buttons sit at the very end of tab+ // order, and nothing previously moved focus there directly. Alt+Shift+N+ // focuses the newest toast's first control (falling back to the toast body,+ // which is always `tabIndex={-1}`); Escape while focus is inside a toast+ // returns it to whatever held it before the jump.+ useEffect(() => {+ function onKeyDown(e) {+ if (e.altKey && e.shiftKey && !e.metaKey && !e.ctrlKey && e.code === 'KeyN') {+ // `code`, not `key` — macOS remaps Option+letter to a different+ // character (Option+Shift+N is typically `˜`), which would silently+ // break the shortcut on every Mac if matched on `key`. Not routed+ // through `shouldIgnoreGlobalKey`: that predicate drops every+ // Alt-chorded keydown by default, and Alt is exactly the chord this+ // shortcut needs, so the editable-target guard is applied directly+ // instead.+ if (isEditableTarget(e.target)) return;+ // An open `aria-modal` dialog owns the focus trap (WCAG 2.4.3) —+ // jumping focus out to a toast behind it would break that trap, so+ // this stands down exactly like `shouldIgnoreGlobalKey`'s dialog+ // guard does for the shortcut hooks that route through it.+ if (document.querySelector('[aria-modal="true"]')) return;+ const region = regionRef.current;+ const newest = items[items.length - 1];+ if (!region || !newest) return;+ const toastEl = region.querySelector(`[data-toast-id="${newest.id}"]`);+ if (!toastEl) return;+ const focusTarget = toastEl.tagName === 'BUTTON'+ ? toastEl+ : (toastEl.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])') ?? toastEl);+ e.preventDefault();+ returnFocusRef.current = document.activeElement;+ focusTarget.focus();+ return;+ }+ if (e.key === 'Escape' && returnFocusRef.current && regionRef.current?.contains(document.activeElement)) {+ const toReturn = returnFocusRef.current;+ returnFocusRef.current = null;+ toReturn.focus();+ }+ }+ document.addEventListener('keydown', onKeyDown);+ return () => document.removeEventListener('keydown', onKeyDown);+ }, [items]);+const posClass = {'bottom-right': 'bottom-4 right-4 items-end','bottom-left': 'bottom-4 left-4 items-start',@@ -149,9 +203,11 @@ export function Toaster({ position = 'bottom-right', toastOptions = {} }) {// per-toast rather than on the container avoids the whole stack being// re-read when one entry changes.<div+ ref={regionRef}className={`fixed ${posClass} z-[9999] flex flex-col gap-2 pointer-events-none`}role="region"aria-label="Notifications"+ aria-keyshortcuts="Alt+Shift+N">{items.map(t => (<ToastItem key={t.id} t={t} toastOptions={toastOptions} />@@ -207,6 +263,38 @@ function ToastItem({ t, toastOptions }) {return () => clearTimeout(timer);}, [collapsible, collapsed, held, collapseAfter]);+ // The finite-duration dismiss timer, moved here from `add()` (#8117) so it+ // can pause while `held` and resume with the time that was actually left,+ // instead of firing on a fixed wall-clock deadline a hovering mouse or a+ // focused button couldn't touch.+ //+ // `remainingRef` is the ms left on the countdown; it survives across+ // pause/resume because a ref, unlike state, doesn't trigger its own+ // re-render/effect cycle. `prevIdentityRef` detects a same-id content swap+ // (a loading→success toast) the same way the collapse-reset effect above+ // does — comparing `t.content`/`t.type` by reference, which only change+ // when `add()` actually ran — and restarts the countdown from the NEW+ // duration rather than treating the swap as a re-render of the old one.+ const remainingRef = useRef(t.duration);+ const prevIdentityRef = useRef([t.content, t.type]);++ useEffect(() => {+ const [prevContent, prevType] = prevIdentityRef.current;+ const isNewArm = prevContent !== t.content || prevType !== t.type;+ prevIdentityRef.current = [t.content, t.type];++ if (t.duration === Infinity) return undefined;+ if (isNewArm) remainingRef.current = t.duration;+ if (held) return undefined;++ const start = Date.now();+ const timer = setTimeout(() => dismiss(t.id), remainingRef.current);+ return () => {+ clearTimeout(timer);+ remainingRef.current = Math.max(0, remainingRef.current - (Date.now() - start));+ };+ }, [t.id, t.duration, t.content, t.type, held]);+// Re-entering `add()` with the same id replaces the entry in place (a// loading→success swap, a coalesced AI-status error picking up another// failure). That toast has something new to say, so unfold it — otherwise the@@ -266,6 +354,7 @@ function ToastItem({ t, toastOptions }) {// folds it away again on its own.<buttontype="button"+ data-toast-id={t.id}onClick={e => {refocusOnExpand.current = e.detail === 0;setCollapsed(false);@@ -278,6 +367,7 @@ function ToastItem({ t, toastOptions }) {)}<divref={bodyRef}+ data-toast-id={t.id}style={bodyStyle}// Focusable only programmatically (see the refocus effect); -1 keeps// the body itself out of the tab sequence so it never sits between the@@ -295,6 +385,15 @@ function ToastItem({ t, toastOptions }) {{iconNode && <span className={`shrink-0 ${iconClass} ${iconBoxClass}`} aria-hidden="true">{iconNode}</span>}<div className="flex-1 min-w-0">{typeof t.content === 'function' ? t.content({ id: t.id }) : <span>{t.content}</span>}+ {/* Render-prop toasts are the actionable ones — an Undo/Reconcile/+ Rate button that a screen-reader user hears announced but can't+ reach in the normal tab order (the Toaster mounts last in+ `main.jsx`). Naming the shortcut in the same live announcement+ tells them how to get there without needing sighted discovery of+ a global shortcuts list. */}+ {typeof t.content === 'function' && (+ <span className="sr-only"> Press Alt+Shift+N to reach its actions.</span>+ )}</div></div></>diff --git a/client/src/components/ui/Toast.test.jsx b/client/src/components/ui/Toast.test.jsxindex 28a67fa91a..24c74e6c7b 100644--- a/client/src/components/ui/Toast.test.jsx+++ b/client/src/components/ui/Toast.test.jsx@@ -300,6 +300,18 @@ describe('long-lived toasts stop blocking the page', () => {expect(screen.getByRole('button', { name: 'Show notification: Stuck forever' })).toBeVisible();});+ it('reveals the Alt+Shift+N hint to screen readers on an actionable (render-prop) toast', () => {+ act(() => {+ toast(() => <button type="button">Reconcile</button>, { duration: Infinity, label: 'Install out of sync' });+ });+ expect(screen.getByRole('status')).toHaveTextContent('Press Alt+Shift+N to reach its actions.');+ });++ it('does not add the hint to a plain string toast', () => {+ act(() => { toast('Export complete'); });+ expect(screen.getByRole('status')).not.toHaveTextContent('Alt+Shift+N');+ });+it('hides rather than unmounts, so a self-dismissing toast keeps its timers', () => {const unmounted = vi.fn();function SelfManaging() {@@ -316,3 +328,164 @@ describe('long-lived toasts stop blocking the page', () => {expect(screen.getByText('Agent finished')).toBeInTheDocument();});});++/**+ * #8117: a finite toast's dismiss timer used to be armed once, outside React,+ * at creation — hover and focus could not touch it, so a keyboard user+ * reaching for an Undo button lost it mid-reach, and a mouse user hovering+ * over Undo could lose it while still reading. It now lives inside+ * `ToastItem` and pauses/resumes around the same `held` (hover-or-focus-+ * within) state that already gates the pill collapse above.+ */+describe('finite toasts pause their dismiss timer while held', () => {+ const advance = (ms) => act(() => { vi.advanceTimersByTime(ms); });++ beforeEach(() => {+ vi.useFakeTimers();+ render(<Toaster />);+ });++ it('stays present past its duration while hovered, then dismisses after the remaining time once released', () => {+ act(() => { toast('Dismissed: a warning · Undo', { duration: 8000 }); });++ const status = screen.getByRole('status');+ fireEvent.mouseEnter(status);++ // Well past the original 8s deadline — still here because the pointer is+ // holding it open.+ advance(20000);+ expect(screen.getByRole('status')).toBeVisible();++ fireEvent.mouseLeave(status);++ // Hover started immediately after creation, so none of the original 8s+ // had elapsed — the full 8s is still owed after release.+ advance(7000);+ expect(screen.getByRole('status')).toBeVisible();+ advance(1000);+ expect(screen.queryByRole('status')).toBeNull();+ });++ it('stays present past its duration while focus is inside it, then dismisses after release', () => {+ act(() => {+ toast(() => <button type="button">Undo</button>, { duration: 8000, label: 'Comment fix applied' });+ });++ const button = screen.getByRole('button', { name: 'Undo' });+ fireEvent.focus(button);++ advance(20000);+ expect(screen.getByRole('button', { name: 'Undo' })).toBeVisible();++ fireEvent.blur(button);+ advance(8000);+ expect(screen.queryByRole('status')).toBeNull();+ });++ it('dismisses only after the REMAINING time, not the full duration, once released partway through', () => {+ act(() => { toast('Saved with a note', { duration: 8000 }); });++ const status = screen.getByRole('status');+ advance(5000); // 3s left on the clock+ fireEvent.mouseEnter(status);+ advance(10000); // held well past the original deadline+ fireEvent.mouseLeave(status);++ advance(2999);+ expect(screen.getByRole('status')).toBeVisible();+ advance(1);+ expect(screen.queryByRole('status')).toBeNull();+ });++ it('restarts the countdown from the new duration on a same-id content swap (loading → success)', () => {+ act(() => { toast.loading('Applying fix...', { id: 'apply-fix' }); });+ advance(50000); // loading is Infinity — never dismisses on its own++ act(() => { toast.success('Fix applied · Undo', { id: 'apply-fix', duration: 6000 }); });++ // The new 6s duration, not any leftover from the (nonexistent) loading timer.+ advance(5999);+ expect(screen.getByRole('status')).toBeVisible();+ advance(1);+ expect(screen.queryByRole('status')).toBeNull();+ });+});++describe('Alt+Shift+N focuses the newest toast, and Escape returns focus', () => {+ const advance = (ms) => act(() => { vi.advanceTimersByTime(ms); });++ beforeEach(() => {+ vi.useFakeTimers();+ });++ const pressJumpShortcut = () => {+ fireEvent.keyDown(document, { altKey: true, shiftKey: true, code: 'KeyN' });+ };++ it("focuses the newest toast's first button in one keystroke", () => {+ render(<Toaster />);+ act(() => {+ toast(() => <button type="button">Undo</button>, { duration: Infinity, label: 'Dismissed a warning' });+ });++ pressJumpShortcut();+ expect(document.activeElement).toBe(screen.getByRole('button', { name: 'Undo' }));+ });++ it('holds the toast open once the jump lands focus inside it, even past its duration', () => {+ render(<Toaster />);+ act(() => {+ toast(() => <button type="button">Undo</button>, { duration: 8000, label: 'Dismissed a warning' });+ });++ pressJumpShortcut();+ advance(20000);+ expect(screen.getByRole('button', { name: 'Undo' })).toBeVisible();+ });++ it('falls back to the toast body when it has no focusable control', () => {+ render(<Toaster />);+ act(() => { toast('Backup finished'); });++ pressJumpShortcut();+ expect(document.activeElement).toBe(screen.getByRole('status'));+ });++ it('ignores the shortcut while typing in an editable field', () => {+ render(+ <>+ <input aria-label="search" />+ <Toaster />+ </>+ );+ act(() => { toast(() => <button type="button">Undo</button>, { duration: Infinity, label: 'x' }); });++ const input = screen.getByRole('textbox', { name: 'search' });+ input.focus();+ fireEvent.keyDown(input, { altKey: true, shiftKey: true, code: 'KeyN' });++ expect(document.activeElement).toBe(input);+ });++ it('restores focus to the previously focused element on Escape', () => {+ render(+ <>+ <button type="button">Page button</button>+ <Toaster />+ </>+ );+ act(() => {+ toast(() => <button type="button">Undo</button>, { duration: Infinity, label: 'x' });+ });++ const pageButton = screen.getByRole('button', { name: 'Page button' });+ pageButton.focus();+ expect(document.activeElement).toBe(pageButton);++ pressJumpShortcut();+ expect(document.activeElement).toBe(screen.getByRole('button', { name: 'Undo' }));++ fireEvent.keyDown(document.activeElement, { key: 'Escape' });+ expect(document.activeElement).toBe(pageButton);+ });+});