mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-08 00:57:16 -07:00
fix(core): address memory leaks in oauth flow, chat history, and shell parsing
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { useEffect, useReducer, useRef } from 'react';
|
||||
import { useEffect, useReducer, useRef, useCallback } from 'react';
|
||||
import { setTimeout as setTimeoutPromise } from 'node:timers/promises';
|
||||
import * as path from 'node:path';
|
||||
import {
|
||||
@@ -224,15 +224,15 @@ export function useAtCompletion(props: UseAtCompletionProps): void {
|
||||
setIsLoadingSuggestions(state.isLoading);
|
||||
}, [state.isLoading, setIsLoadingSuggestions]);
|
||||
|
||||
const resetFileSearchState = () => {
|
||||
const resetFileSearchState = useCallback(() => {
|
||||
fileSearchMap.current.clear();
|
||||
initEpoch.current += 1;
|
||||
dispatch({ type: 'RESET' });
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
resetFileSearchState();
|
||||
}, [cwd, config]);
|
||||
}, [cwd, config, resetFileSearchState]);
|
||||
|
||||
useEffect(() => {
|
||||
const workspaceContext = config?.getWorkspaceContext?.();
|
||||
@@ -242,7 +242,7 @@ export function useAtCompletion(props: UseAtCompletionProps): void {
|
||||
workspaceContext.onDirectoriesChanged(resetFileSearchState);
|
||||
|
||||
return unsubscribe;
|
||||
}, [config]);
|
||||
}, [config, resetFileSearchState]);
|
||||
|
||||
// Reacts to user input (`pattern`) ONLY.
|
||||
useEffect(() => {
|
||||
|
||||
@@ -83,7 +83,12 @@ export function useHistory({
|
||||
return prevHistory; // Don't add the duplicate
|
||||
}
|
||||
}
|
||||
return [...prevHistory, newItem];
|
||||
const newHistory = [...prevHistory, newItem];
|
||||
// Enforce a hard limit of 1000 items to prevent unbounded memory growth
|
||||
if (newHistory.length > 1000) {
|
||||
return newHistory.slice(newHistory.length - 1000);
|
||||
}
|
||||
return newHistory;
|
||||
});
|
||||
|
||||
// Record UI-specific messages, but don't do it if we're actually loading
|
||||
|
||||
Reference in New Issue
Block a user