The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): board switcher crashed on every render
Brooklyn Nicholsond9d1ee835774
diff --git a/apps/desktop/src/plugins/kanban/board-switcher.test.tsx b/apps/desktop/src/plugins/kanban/board-switcher.test.tsxnew file mode 100644index 00000000000..b48df31f63e--- /dev/null+++ b/apps/desktop/src/plugins/kanban/board-switcher.test.tsx@@ -0,0 +1,39 @@+import { QueryClient, QueryClientProvider } from '@tanstack/react-query'+import { cleanup, render, screen } from '@testing-library/react'+import { afterEach, describe, expect, it, vi } from 'vitest'++import type * as KanbanApi from './api'+import { $boardSlug } from './api'+import { BoardSwitcher } from './board-switcher'++vi.mock('./api', async importOriginal => ({+ ...(await importOriginal<typeof KanbanApi>()),+ fetchBoards: vi.fn(async () => ({+ boards: [{ name: 'Shipping', project_id: null, slug: 'shipping', total: 3 }],+ current: 'shipping'+ }))+}))++afterEach(() => {+ cleanup()+ $boardSlug.set('')+})++const mount = () =>+ render(+ <QueryClientProvider client={new QueryClient({ defaultOptions: { queries: { retry: false } } })}>+ <BoardSwitcher />+ </QueryClientProvider>+ )++describe('board switcher', () => {+ // The rename and settings dialogs stay mounted while closed, so they render+ // with a null board on every pass. Reading the slug inside their mutation+ // callback used to crash the whole contribution, because the React Compiler+ // lifts a callback's property reads into its render-time dependency check.+ it('renders while its dialogs are closed', async () => {+ mount()++ expect(await screen.findByText('Shipping')).toBeTruthy()+ })+})diff --git a/apps/desktop/src/plugins/kanban/board-switcher.tsx b/apps/desktop/src/plugins/kanban/board-switcher.tsxindex b890c146f16..972082226b6 100644--- a/apps/desktop/src/plugins/kanban/board-switcher.tsx+++ b/apps/desktop/src/plugins/kanban/board-switcher.tsx@@ -218,6 +218,11 @@ function NewBoardDialog({ onClose, open }: { onClose: () => void; open: booleanfunction RenameBoardDialog({ board, onClose }: { board: BoardMeta | null; onClose: () => void }) {const k = useKanban()const [name, setName] = useState('')+ // The dialog stays mounted while closed, so `board` is null most of the+ // time. Resolve the slug here rather than inside the mutation: the React+ // Compiler lifts a callback's property reads into its render-time+ // dependency check, which would deref that null on every closed render.+ const slug = board?.slug ?? ''useEffect(() => {if (board) {@@ -225,7 +230,7 @@ function RenameBoardDialog({ board, onClose }: { board: BoardMeta | null; onClos}}, [board])- const save = useBoardWrite(() => updateBoard(board!.slug, { name: name.trim() }), onClose)+ const save = useBoardWrite(() => updateBoard(slug, { name: name.trim() }), onClose)const disabled = !name.trim() || save.isPendingreturn (@@ -240,7 +245,7 @@ function RenameBoardDialog({ board, onClose }: { board: BoardMeta | null; onClos<BoardNameFieldonChange={setName}onEnter={() => !disabled && save.mutate()}- slug={board?.slug ?? ''}+ slug={slug}value={name}/></BoardDialog>@@ -250,6 +255,9 @@ function RenameBoardDialog({ board, onClose }: { board: BoardMeta | null; onClosfunction BoardSettingsDialog({ board, onClose }: { board: BoardMeta | null; onClose: () => void }) {const k = useKanban()const [project, setProject] = useState('')+ // Null while closed — see RenameBoardDialog on why this can't live inside+ // the mutation callback.+ const slug = board?.slug ?? ''useEffect(() => {if (board) {@@ -259,7 +267,7 @@ function BoardSettingsDialog({ board, onClose }: { board: BoardMeta | null; onCl// The name lives in the rename dialog; '' clears the scope, which also// drops the mirrored default_workdir on the backend.- const save = useBoardWrite(() => updateBoard(board!.slug, { project_id: project }), onClose)+ const save = useBoardWrite(() => updateBoard(slug, { project_id: project }), onClose)return (<BoardDialog