mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-18 14:00:27 -07:00
fix(cli): prevent race condition when restoring prompt after context overflow (#13473)
This commit is contained in:
@@ -170,6 +170,7 @@ export const AppContainer = (props: AppContainerProps) => {
|
||||
null,
|
||||
);
|
||||
const [copyModeEnabled, setCopyModeEnabled] = useState(false);
|
||||
const [pendingRestorePrompt, setPendingRestorePrompt] = useState(false);
|
||||
|
||||
const [shellModeActive, setShellModeActive] = useState(false);
|
||||
const [modelSwitchedFromQuotaError, setModelSwitchedFromQuotaError] =
|
||||
@@ -666,9 +667,32 @@ Logging in with Google... Please restart Gemini CLI to continue.
|
||||
);
|
||||
|
||||
const onCancelSubmit = useCallback((shouldRestorePrompt?: boolean) => {
|
||||
cancelHandlerRef.current(shouldRestorePrompt);
|
||||
if (shouldRestorePrompt) {
|
||||
setPendingRestorePrompt(true);
|
||||
} else {
|
||||
setPendingRestorePrompt(false);
|
||||
cancelHandlerRef.current(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (pendingRestorePrompt) {
|
||||
const lastHistoryUserMsg = historyManager.history.findLast(
|
||||
(h) => h.type === 'user',
|
||||
);
|
||||
const lastUserMsg = userMessages.at(-1);
|
||||
|
||||
if (
|
||||
!lastHistoryUserMsg ||
|
||||
(typeof lastHistoryUserMsg.text === 'string' &&
|
||||
lastHistoryUserMsg.text === lastUserMsg)
|
||||
) {
|
||||
cancelHandlerRef.current(true);
|
||||
setPendingRestorePrompt(false);
|
||||
}
|
||||
}
|
||||
}, [pendingRestorePrompt, userMessages, historyManager.history]);
|
||||
|
||||
const {
|
||||
streamingState,
|
||||
submitQuery,
|
||||
|
||||
Reference in New Issue
Block a user