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 (