From 632ce132bb02908db24fe36c0e828e748b914cae Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Wed, 22 Jul 2026 22:09:18 -0400 Subject: [PATCH] fix(frontend): stabilize ScheduleJobDialog render loop and improve accessibility (#315) Resolve a "Maximum update depth exceeded" render loop in ScheduleJobDialog while prompt templates are loading, and add accessibility labels across the frontend. Also unregister the service worker in dev to avoid stale caches. - ScheduleJobDialog: use a stable EMPTY_TEMPLATES constant and split template matching into its own effect keyed on [templates, job, open] instead of running inside the init effect that depends on templates - Add ScheduleJobDialog.loading.test.tsx regression test for the loading state - serviceWorker: unregister existing registrations and clear caches in DEV so stale workers do not serve outdated assets locally - App: replace shell div with semantic
- SettingsDialog: add sr-only DialogTitle for screen readers - Add aria-labels to icon-only buttons in back-button, combobox, header, GlobalSchedules, and Repos - index.html: add mobile-web-app-capable meta --- frontend/index.html | 1 + frontend/src/App.tsx | 4 +- .../ScheduleJobDialog.loading.test.tsx | 77 +++++++++++++++++++ .../schedules/ScheduleJobDialog.tsx | 16 +++- .../components/settings/SettingsDialog.tsx | 3 +- frontend/src/components/ui/back-button.tsx | 1 + frontend/src/components/ui/combobox.tsx | 2 + frontend/src/components/ui/header.tsx | 1 + frontend/src/lib/serviceWorker.ts | 18 +++++ frontend/src/pages/GlobalSchedules.tsx | 8 +- frontend/src/pages/Repos.tsx | 1 + 11 files changed, 123 insertions(+), 9 deletions(-) create mode 100644 frontend/src/components/schedules/ScheduleJobDialog.loading.test.tsx diff --git a/frontend/index.html b/frontend/index.html index 90991b2a..ea7401ca 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -23,6 +23,7 @@ + diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index f4570521..a6327852 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -159,9 +159,9 @@ function AppShell() {
-
+
-
+
diff --git a/frontend/src/components/schedules/ScheduleJobDialog.loading.test.tsx b/frontend/src/components/schedules/ScheduleJobDialog.loading.test.tsx new file mode 100644 index 00000000..024dc165 --- /dev/null +++ b/frontend/src/components/schedules/ScheduleJobDialog.loading.test.tsx @@ -0,0 +1,77 @@ +import { describe, it, expect, vi, beforeEach } from 'vitest' +import { render, screen, waitFor } from '@testing-library/react' +import { QueryClient, QueryClientProvider } from '@tanstack/react-query' +import { ScheduleJobDialog } from './ScheduleJobDialog' + +// jsdom does not implement scrollIntoView +Element.prototype.scrollIntoView = vi.fn() + +// Reproduces the "Maximum update depth exceeded" crash: while the prompt +// templates query is loading, the hook returns `data: undefined`. The +// component's `= EMPTY_TEMPLATES` fallback must stay referentially stable so +// the init effect does not re-fire every render. +vi.mock('@/hooks/usePromptTemplates', () => ({ + usePromptTemplates: () => ({ data: undefined, isLoading: true }), + useCreatePromptTemplate: () => ({ mutate: vi.fn(), isPending: false }), + useUpdatePromptTemplate: () => ({ mutate: vi.fn(), isPending: false }), + useDeletePromptTemplate: () => ({ mutate: vi.fn(), isPending: false }), +})) + +vi.mock('@/api/providers', () => ({ + getProvidersWithModels: () => Promise.resolve([]), +})) + +vi.mock('@/api/opencode', () => ({ + createOpenCodeClient: () => ({ + listAgents: () => Promise.resolve([]), + getConfig: () => Promise.resolve(null), + }), +})) + +vi.mock('@/api/settings', () => ({ + settingsApi: { + listManagedSkills: () => Promise.resolve([]), + }, +})) + +vi.mock('@/api/repos', () => ({ + listRepos: () => Promise.resolve([]), + listBranches: () => Promise.resolve({ branches: [], status: { ahead: 0, behind: 0 } }), +})) + +function createWrapper() { + const queryClient = new QueryClient({ + defaultOptions: { + queries: { retry: false }, + mutations: { retry: false }, + }, + }) + return ({ children }: { children: React.ReactNode }) => ( + {children} + ) +} + +describe('ScheduleJobDialog — templates loading', () => { + beforeEach(() => { + vi.clearAllMocks() + }) + + it('renders without an infinite render loop while templates are loading', async () => { + render( + , + { wrapper: createWrapper() }, + ) + + await waitFor(() => { + expect(screen.getByText('New schedule')).toBeInTheDocument() + }) + }) +}) diff --git a/frontend/src/components/schedules/ScheduleJobDialog.tsx b/frontend/src/components/schedules/ScheduleJobDialog.tsx index fbc5f96c..8d1c677a 100644 --- a/frontend/src/components/schedules/ScheduleJobDialog.tsx +++ b/frontend/src/components/schedules/ScheduleJobDialog.tsx @@ -29,6 +29,8 @@ import { TimingTab } from './TimingTab' import { PromptTab } from './PromptTab' import { SkillsTab } from './SkillsTab' +const EMPTY_TEMPLATES: PromptTemplate[] = [] + type ScheduleJobDialogProps = { open: boolean onOpenChange: (open: boolean) => void @@ -68,7 +70,7 @@ export function ScheduleJobDialog({ open, onOpenChange, job, isSaving, onSubmit, const [editingTemplate, setEditingTemplate] = useState(undefined) const [deletingTemplateId, setDeletingTemplateId] = useState(null) - const { data: templates = [] } = usePromptTemplates() + const { data: templates = EMPTY_TEMPLATES } = usePromptTemplates() const deleteTemplateMutation = useDeletePromptTemplate() const { data: providerModels = [] } = useQuery({ @@ -212,8 +214,6 @@ export function ScheduleJobDialog({ open, onOpenChange, job, isSaving, onSubmit, setAgentSlug(job?.agentSlug ?? '') setModel(job?.model ?? '') setPrompt(job?.prompt ?? '') - const matchingTemplate = templates.find((template) => template.prompt === (job?.prompt ?? '')) - setSelectedPromptTemplateId(matchingTemplate ? matchingTemplate.id : null) const initialSkillSlugs = job?.skillMetadata?.skillSlugs ?? [] const initialSkillNotes = job?.skillMetadata?.notes ?? '' setSkillSlugs(initialSkillSlugs) @@ -223,7 +223,15 @@ export function ScheduleJobDialog({ open, onOpenChange, job, isSaving, onSubmit, setBranch(job?.branch ?? '') setAllowExternalDirectory(job?.permissionConfig?.allowExternalDirectory ?? false) setBashDenyPatterns(job?.permissionConfig?.bashDenyPatterns ?? [...DEFAULT_DESTRUCTIVE_BASH_PATTERNS]) - }, [job, open, templates]) + }, [job, open]) + + useEffect(() => { + if (!open) { + return + } + const matchingTemplate = templates.find((template) => template.prompt === (job?.prompt ?? '')) + setSelectedPromptTemplateId(matchingTemplate ? matchingTemplate.id : null) + }, [templates, job, open]) const applyPromptTemplate = (template: PromptTemplate) => { setSelectedPromptTemplateId(template.id) diff --git a/frontend/src/components/settings/SettingsDialog.tsx b/frontend/src/components/settings/SettingsDialog.tsx index a72124c6..9a2bb537 100644 --- a/frontend/src/components/settings/SettingsDialog.tsx +++ b/frontend/src/components/settings/SettingsDialog.tsx @@ -12,7 +12,7 @@ import { AccountSettings } from '@/components/settings/AccountSettings' import { VoiceSettings } from '@/components/settings/VoiceSettings' import { NotificationSettings } from '@/components/settings/NotificationSettings' import { VersionSelectDialog } from '@/components/settings/VersionSelectDialog' -import { Dialog, DialogContent } from '@/components/ui/dialog' +import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog' import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs' import { Settings2, Keyboard, Code, ChevronLeft, Key, GitBranch, User, Volume2, Bell, X } from 'lucide-react' import { Button } from '@/components/ui/button' @@ -109,6 +109,7 @@ export function SettingsDialog() { onFocusOutside={(e) => e.preventDefault()} onPointerDownOutside={(e) => e.preventDefault()} > + Settings

diff --git a/frontend/src/components/ui/back-button.tsx b/frontend/src/components/ui/back-button.tsx index 9557feb3..c5ed3dc3 100644 --- a/frontend/src/components/ui/back-button.tsx +++ b/frontend/src/components/ui/back-button.tsx @@ -16,6 +16,7 @@ export function BackButton({ to = "/", className = "" }: BackButtonProps) { return (