The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(chat): pin composer slot identity across host re-renders
Shanu85aae36d3c1d
diff --git a/app/src/features/conversations/components/AssistantUiChat.slots.test.tsx b/app/src/features/conversations/components/AssistantUiChat.slots.test.tsxnew file mode 100644index 0000000000..6f016ee6e6--- /dev/null+++ b/app/src/features/conversations/components/AssistantUiChat.slots.test.tsx@@ -0,0 +1,139 @@+/**+ * Composer slot identity on the assistant-ui chat surface.+ *+ * `thread.tsx` renders each host slot **by type**, so a slot defined as a+ * callback with a changing dep list hands React a new element type and the+ * subtree unmounts and remounts on every host render (#6246). The slots now+ * hold a constant identity and read their props through a ref instead.+ *+ * That trade has a failure mode of its own: a frozen slot that never re-renders+ * would show stale props forever. It does not happen here because nothing in+ * `thread.tsx` is memoized — the whole subtree re-renders with its host — and+ * these tests pin that down, because it is the only thing keeping the stable+ * slots correct.+ */+import { combineReducers, configureStore } from '@reduxjs/toolkit';+import { render, screen } from '@testing-library/react';+import { Provider } from 'react-redux';+import { describe, expect, it, vi } from 'vitest';++import chatRuntimeReducer from '../../../store/chatRuntimeSlice';+import mascotReducer from '../../../store/mascotSlice';+import threadReducer from '../../../store/threadSlice';+import { AssistantUiChat } from './AssistantUiChat';+import type { ThreadGoalController } from './ThreadGoalChip';++const THREAD_ID = 't-slots';++function buildStore() {+ return configureStore({+ reducer: combineReducers({+ thread: threadReducer,+ chatRuntime: chatRuntimeReducer,+ mascot: mascotReducer,+ }),+ preloadedState: {+ thread: {+ threads: [+ {+ id: THREAD_ID,+ title: 'Slots thread',+ chatId: null,+ isActive: false,+ messageCount: 0,+ lastMessageAt: '2026-01-01T00:00:00.000Z',+ createdAt: '2026-01-01T00:00:00.000Z',+ labels: [],+ },+ ],+ selectedThreadId: THREAD_ID,+ activeThreadIds: {},+ welcomeThreadId: null,+ messagesByThreadId: { [THREAD_ID]: [] },+ messages: [],+ isLoadingThreads: false,+ isLoadingMessages: false,+ messagesError: null,+ },+ } as never,+ });+}++/**+ * A fresh controller object every time, the way `useThreadGoal` returns one:+ * it is a bare object literal, so its identity changes on every host render.+ */+function goalController(overrides: Partial<ThreadGoalController> = {}): ThreadGoalController {+ return {+ threadId: THREAD_ID,+ goal: null,+ expanded: false,+ draft: '',+ busy: false,+ setDraft: vi.fn(),+ open: vi.fn(),+ close: vi.fn(),+ toggle: vi.fn(),+ save: vi.fn(),+ complete: vi.fn(),+ pause: vi.fn(),+ resume: vi.fn(),+ clear: vi.fn(),+ ...overrides,+ };+}++function chat(threadGoal: ThreadGoalController, onOpenHumanMode?: () => void) {+ return (+ <AssistantUiChat+ threadGoal={threadGoal}+ model={null}+ onModelChange={vi.fn()}+ inputValue=""+ onInputValueChange={vi.fn()}+ attachments={[]}+ onAttachFiles={vi.fn()}+ onRemoveAttachment={vi.fn()}+ maxAttachments={5}+ attachmentsEnabled={false}+ attachmentInteractionBlocked={false}+ onAttachmentOnlySend={vi.fn()}+ onOpenHumanMode={onOpenHumanMode}+ />+ );+}++describe('assistant-ui composer slots', () => {+ it('shows the thread-goal editor once the controller expands', async () => {+ const store = buildStore();+ const { rerender } = render(<Provider store={store}>{chat(goalController())}</Provider>);++ expect(screen.queryByPlaceholderText('What should this thread accomplish?')).toBeNull();++ // The host re-renders with a new controller object carrying `expanded`.+ // `ComposerExtras` holds a constant identity and has no dependency on it,+ // so this only appears if the slot re-renders with its host.+ rerender(<Provider store={store}>{chat(goalController({ expanded: true }))}</Provider>);++ expect(+ await screen.findByPlaceholderText('What should this thread accomplish?')+ ).toBeInTheDocument();+ });++ it('keeps the idle mascot button mounted across a host re-render', () => {+ const store = buildStore();+ const navigate = vi.fn();+ // A fresh arrow per render, exactly as `Conversations` passes it+ // (`onOpenHumanMode={() => navigate('/human')}`). That changing identity is+ // what used to remount the slot.+ const { rerender } = render(+ <Provider store={store}>{chat(goalController(), () => navigate('/human'))}</Provider>+ );++ const button = screen.getByTestId('composer-human-mode');++ rerender(<Provider store={store}>{chat(goalController(), () => navigate('/human'))}</Provider>);++ expect(screen.getByTestId('composer-human-mode')).toBe(button);+ });+});diff --git a/app/src/pages/__tests__/Conversations.attachments.test.tsx b/app/src/pages/__tests__/Conversations.attachments.test.tsxindex 0ab3bc5cc1..7869429c22 100644--- a/app/src/pages/__tests__/Conversations.attachments.test.tsx+++ b/app/src/pages/__tests__/Conversations.attachments.test.tsx@@ -328,6 +328,55 @@ describe('Conversations — attachment feature', () => {});});+ // The composer slots are handed to assistant-ui by type, so an unstable slot+ // identity remounts them on every host render. For the hidden file input that+ // means a pick made after any re-render lands on a detached element and never+ // reaches React; for the preview it means the image restarts decoding before+ // it can paint. Both were #6246.+ it('keeps the file input mounted across a host re-render, so a slow pick still lands', async () => {+ const { textarea } = await renderWithSelectedThread();++ const fileInput = document.querySelector('input[type="file"]') as HTMLInputElement;+ expect(fileInput).not.toBeNull();++ // Stands in for whatever re-renders the chat while the native dialog is+ // open: a keystroke, a streaming token, a socket event.+ await act(async () => {+ textarea.textContent = 'still typing';+ fireEvent.input(textarea, { data: 'still typing', inputType: 'insertText' });+ });++ expect(document.querySelector('input[type="file"]')).toBe(fileInput);++ const file = makeFile('late-pick.png', 'image/png', 512);+ await act(async () => {+ fireEvent.change(fileInput, { target: { files: [file] } });+ });++ await waitFor(() => {+ expect(screen.getByText('late-pick.png')).toBeInTheDocument();+ });+ });++ it('keeps the attachment preview image mounted across a host re-render', async () => {+ const { textarea } = await renderWithSelectedThread();++ const fileInput = document.querySelector('input[type="file"]') as HTMLInputElement;+ const file = makeFile('preview.png', 'image/png', 512);+ await act(async () => {+ fireEvent.change(fileInput, { target: { files: [file] } });+ });++ const image = await screen.findByAltText('preview.png');++ await act(async () => {+ textarea.textContent = 'typing after attaching';+ fireEvent.input(textarea, { data: 'typing after attaching', inputType: 'insertText' });+ });++ expect(screen.getByAltText('preview.png')).toBe(image);+ });+it('shows too-many error when selecting more than 4 images', async () => {await renderWithSelectedThread();