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: retain page focus across bulk media destination actions (#9881)
Adam Eivy99e1e7e288d8
diff --git a/client/src/pages/MediaCollectionDetail.jsx b/client/src/pages/MediaCollectionDetail.jsxindex bb9f32a7fa..133deacdf1 100644--- a/client/src/pages/MediaCollectionDetail.jsx+++ b/client/src/pages/MediaCollectionDetail.jsx@@ -73,6 +73,17 @@ export default function MediaCollectionDetail() {const [pickerMode, setPickerMode] = useState(null);const moveBtnRef = useRef(null);const copyBtnRef = useRef(null);+ const pageFocusRef = useRef(null);+ const returningBulkFocus = useRef(false);+ // Bulk selection disables its opener, then removes that toolbar on success.+ // The page region survives loading and selection changes as a safe fallback.+ useEffect(() => {+ if (!returningBulkFocus.current) return;+ if (document.activeElement === document.body || document.activeElement?.disabled) {+ pageFocusRef.current?.focus({ preventScroll: true });+ }+ if (!bulkBusy) returningBulkFocus.current = false;+ }, [bulkBusy, loading]);const { annotations, toggleStar, updateAnnotation, getCardProps } = useMediaAnnotations();const page = useGalleryPage({ collectionId: id, kind: 'all' }, { media: true });@@ -252,6 +263,7 @@ export default function MediaCollectionDetail() {const bulkMoveOrCopy = async (targetId, targetName) => {if (selectedItems.length === 0 || !pickerMode) return;const mode = pickerMode;+ returningBulkFocus.current = true;setPickerMode(null);setBulkBusy(true);const placedKeys = new Set();@@ -337,13 +349,15 @@ export default function MediaCollectionDetail() {if (loading || (page.loading && page.items.length === 0)) {return (- <PageSkeleton- label="Loading collection"- titleWidthClass="w-56"- layout="grid"- cards={10}- gridColsClass="grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5"- />+ <div ref={pageFocusRef} tabIndex={-1} role="region" aria-label="Media collection">+ <PageSkeleton+ label="Loading collection"+ titleWidthClass="w-56"+ layout="grid"+ cards={10}+ gridColsClass="grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5"+ />+ </div>);}if (!collection) return (@@ -407,7 +421,7 @@ export default function MediaCollectionDetail() {};return (- <div className="space-y-4">+ <div ref={pageFocusRef} tabIndex={-1} role="region" aria-label="Media collection" className="space-y-4"><div className="flex items-center gap-3"><Link to="/media/collections" className="text-gray-400 hover:text-white" title="Back"><ArrowLeft className="w-5 h-5" />diff --git a/client/src/pages/MediaCollectionDetail.test.jsx b/client/src/pages/MediaCollectionDetail.test.jsxindex 3e1a9dd000..22dd69a9d6 100644--- a/client/src/pages/MediaCollectionDetail.test.jsx+++ b/client/src/pages/MediaCollectionDetail.test.jsx@@ -1,5 +1,5 @@import { describe, it, expect, vi, beforeEach } from 'vitest';-import { render, screen, waitFor } from '@testing-library/react';+import { act, render, screen, waitFor } from '@testing-library/react';import userEvent from '@testing-library/user-event';import { MemoryRouter, Route, Routes } from 'react-router';@@ -389,6 +389,22 @@ describe('MediaCollectionDetail — bulkMoveOrCopy move/remove failures', () =>expect(screen.queryByText(/of 3 selected/)).toBeNull();});+ it('keeps a usable page focus target while a destination action disables and removes its opener', async () => {+ let finishAdd;+ mockAddMediaCollectionItem.mockImplementationOnce(() => new Promise(resolve => { finishAdd = resolve; }));+ const user = userEvent.setup();+ renderReal();+ await selectAllAndMove(user);+ const region = screen.getByRole('region', { name: 'Media collection' });+ expect(screen.getByRole('button', { name: /move…/i })).toBeDisabled();+ expect(document.activeElement).toBe(region);+ await act(async () => finishAdd(REAL_COLLECTION));+ await waitFor(() => expect(screen.queryByText(/of 3 selected/)).toBeNull());+ expect(document.activeElement).toBe(region);+ await user.tab();+ expect(document.activeElement).toBe(screen.getByRole('link', { name: 'Back' }));+ });+it('reports the removal failure instead of a false success when every removal fails', async () => {mockRemoveMediaCollectionItem.mockRejectedValue(new Error('boom'));const user = userEvent.setup();