fix(cli): fix issue updating a component while rendering a different component (#14319)

This commit is contained in:
Jacob Richman
2025-12-01 17:33:03 -08:00
committed by GitHub
parent 98d7238ed6
commit 1689e9b671
9 changed files with 43 additions and 90 deletions

View File

@@ -1147,7 +1147,6 @@ describe('InputPrompt', () => {
await waitFor(() => {
expect(mockedUseCommandCompletion).toHaveBeenCalledWith(
mockBuffer,
['/test/project/src'],
path.join('test', 'project', 'src'),
mockSlashCommands,
mockCommandContext,
@@ -2268,6 +2267,7 @@ describe('InputPrompt', () => {
describe('queued message editing', () => {
it('should load all queued messages when up arrow is pressed with empty input', async () => {
const mockPopAllMessages = vi.fn();
mockPopAllMessages.mockReturnValue('Message 1\n\nMessage 2\n\nMessage 3');
props.popAllMessages = mockPopAllMessages;
props.buffer.text = '';
@@ -2279,11 +2279,7 @@ describe('InputPrompt', () => {
stdin.write('\u001B[A');
});
await waitFor(() => expect(mockPopAllMessages).toHaveBeenCalled());
const callback = mockPopAllMessages.mock.calls[0][0];
await act(async () => {
callback('Message 1\n\nMessage 2\n\nMessage 3');
});
expect(props.buffer.setText).toHaveBeenCalledWith(
'Message 1\n\nMessage 2\n\nMessage 3',
);
@@ -2311,6 +2307,7 @@ describe('InputPrompt', () => {
it('should handle undefined messages from popAllMessages', async () => {
const mockPopAllMessages = vi.fn();
mockPopAllMessages.mockReturnValue(undefined);
props.popAllMessages = mockPopAllMessages;
props.buffer.text = '';
@@ -2322,10 +2319,6 @@ describe('InputPrompt', () => {
stdin.write('\u001B[A');
});
await waitFor(() => expect(mockPopAllMessages).toHaveBeenCalled());
const callback = mockPopAllMessages.mock.calls[0][0];
await act(async () => {
callback(undefined);
});
expect(props.buffer.setText).not.toHaveBeenCalled();
expect(mockInputHistory.navigateUp).toHaveBeenCalled();
@@ -2353,6 +2346,7 @@ describe('InputPrompt', () => {
it('should handle single queued message', async () => {
const mockPopAllMessages = vi.fn();
mockPopAllMessages.mockReturnValue('Single message');
props.popAllMessages = mockPopAllMessages;
props.buffer.text = '';
@@ -2365,11 +2359,6 @@ describe('InputPrompt', () => {
});
await waitFor(() => expect(mockPopAllMessages).toHaveBeenCalled());
const callback = mockPopAllMessages.mock.calls[0][0];
await act(async () => {
callback('Single message');
});
expect(props.buffer.setText).toHaveBeenCalledWith('Single message');
unmount();
});
@@ -2409,6 +2398,7 @@ describe('InputPrompt', () => {
it('should navigate input history on fresh start when no queued messages exist', async () => {
const mockPopAllMessages = vi.fn();
mockPopAllMessages.mockReturnValue(undefined);
props.popAllMessages = mockPopAllMessages;
props.buffer.text = '';
@@ -2421,11 +2411,6 @@ describe('InputPrompt', () => {
});
await waitFor(() => expect(mockPopAllMessages).toHaveBeenCalled());
const callback = mockPopAllMessages.mock.calls[0][0];
await act(async () => {
callback(undefined);
});
expect(mockInputHistory.navigateUp).toHaveBeenCalled();
expect(props.buffer.setText).not.toHaveBeenCalled();

View File

@@ -83,7 +83,7 @@ export interface InputPromptProps {
isEmbeddedShellFocused?: boolean;
setQueueErrorMessage: (message: string | null) => void;
streamingState: StreamingState;
popAllMessages?: (onPop: (messages: string | undefined) => void) => void;
popAllMessages?: () => string | undefined;
suggestionsPosition?: 'above' | 'below';
setBannerVisible: (visible: boolean) => void;
}
@@ -143,15 +143,6 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
const pasteTimeoutRef = useRef<NodeJS.Timeout | null>(null);
const innerBoxRef = useRef<DOMElement>(null);
const [dirs, setDirs] = useState<readonly string[]>(
config.getWorkspaceContext().getDirectories(),
);
const dirsChanged = config.getWorkspaceContext().getDirectories();
useEffect(() => {
if (dirs.length !== dirsChanged.length) {
setDirs(dirsChanged);
}
}, [dirs.length, dirsChanged]);
const [reverseSearchActive, setReverseSearchActive] = useState(false);
const [commandSearchActive, setCommandSearchActive] = useState(false);
const [textBeforeReverseSearch, setTextBeforeReverseSearch] = useState('');
@@ -165,7 +156,6 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
const completion = useCommandCompletion(
buffer,
dirs,
config.getTargetDir(),
slashCommands,
commandContext,
@@ -310,14 +300,13 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
// Returns true if we should continue with input history navigation
const tryLoadQueuedMessages = useCallback(() => {
if (buffer.text.trim() === '' && popAllMessages) {
popAllMessages((allMessages) => {
if (allMessages) {
buffer.setText(allMessages);
} else {
// No queued messages, proceed with input history
inputHistory.navigateUp();
}
});
const allMessages = popAllMessages();
if (allMessages) {
buffer.setText(allMessages);
} else {
// No queued messages, proceed with input history
inputHistory.navigateUp();
}
return true; // We handled the up arrow key
}
return false;