mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-29 14:34:55 -07:00
refactor(ui): Optimize rendering performance (#8239)
This commit is contained in:
@@ -114,7 +114,7 @@ vi.mock('./useStateAndRef.js', () => ({
|
||||
}
|
||||
ref.current = val;
|
||||
});
|
||||
return [ref, setVal];
|
||||
return [val, ref, setVal];
|
||||
}),
|
||||
}));
|
||||
|
||||
@@ -2216,6 +2216,72 @@ describe('useGeminiStream', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should memoize pendingHistoryItems', () => {
|
||||
mockUseReactToolScheduler.mockReturnValue([
|
||||
[],
|
||||
mockScheduleToolCalls,
|
||||
mockCancelAllToolCalls,
|
||||
mockMarkToolsAsSubmitted,
|
||||
]);
|
||||
|
||||
const { result, rerender } = renderHook(() =>
|
||||
useGeminiStream(
|
||||
mockConfig.getGeminiClient(),
|
||||
[],
|
||||
mockAddItem,
|
||||
mockConfig,
|
||||
mockLoadedSettings,
|
||||
mockOnDebugMessage,
|
||||
mockHandleSlashCommand,
|
||||
false,
|
||||
() => 'vscode' as EditorType,
|
||||
() => {},
|
||||
() => Promise.resolve(),
|
||||
false,
|
||||
() => {},
|
||||
() => {},
|
||||
() => {},
|
||||
() => {},
|
||||
80,
|
||||
24,
|
||||
),
|
||||
);
|
||||
|
||||
const firstResult = result.current.pendingHistoryItems;
|
||||
rerender();
|
||||
const secondResult = result.current.pendingHistoryItems;
|
||||
|
||||
expect(firstResult).toStrictEqual(secondResult);
|
||||
|
||||
const newToolCalls: TrackedToolCall[] = [
|
||||
{
|
||||
request: { callId: 'call1', name: 'tool1', args: {} },
|
||||
status: 'executing',
|
||||
tool: {
|
||||
name: 'tool1',
|
||||
displayName: 'tool1',
|
||||
description: 'desc1',
|
||||
build: vi.fn(),
|
||||
},
|
||||
invocation: {
|
||||
getDescription: () => 'Mock description',
|
||||
},
|
||||
} as unknown as TrackedExecutingToolCall,
|
||||
];
|
||||
|
||||
mockUseReactToolScheduler.mockReturnValue([
|
||||
newToolCalls,
|
||||
mockScheduleToolCalls,
|
||||
mockCancelAllToolCalls,
|
||||
mockMarkToolsAsSubmitted,
|
||||
]);
|
||||
|
||||
rerender();
|
||||
const thirdResult = result.current.pendingHistoryItems;
|
||||
|
||||
expect(thirdResult).not.toStrictEqual(secondResult);
|
||||
});
|
||||
|
||||
it('should reset thought to null when user cancels', async () => {
|
||||
// Mock a stream that yields a thought then gets cancelled
|
||||
mockSendMessageStream.mockReturnValue(
|
||||
|
||||
Reference in New Issue
Block a user