fix(cli): use active sessionId in useLogger and improve resume robustness (#22606)

This commit is contained in:
matt korwel
2026-03-17 14:42:40 -07:00
committed by GitHub
parent 5d4e4c2814
commit e0be1b2afd
6 changed files with 136 additions and 17 deletions
+13 -5
View File
@@ -4,17 +4,25 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { useState, useEffect } from 'react';
import { sessionId, Logger, type Storage } from '@google/gemini-cli-core';
import { useState, useEffect, useContext } from 'react';
import {
sessionId as globalSessionId,
Logger,
type Storage,
} from '@google/gemini-cli-core';
import { ConfigContext } from '../contexts/ConfigContext.js';
/**
* Hook to manage the logger instance.
*/
export const useLogger = (storage: Storage) => {
export const useLogger = (storage: Storage): Logger | null => {
const [logger, setLogger] = useState<Logger | null>(null);
const config = useContext(ConfigContext);
useEffect(() => {
const newLogger = new Logger(sessionId, storage);
const activeSessionId = config?.getSessionId() ?? globalSessionId;
const newLogger = new Logger(activeSessionId, storage);
/**
* Start async initialization, no need to await. Using await slows down the
* time from launch to see the gemini-cli prompt and it's better to not save
@@ -26,7 +34,7 @@ export const useLogger = (storage: Storage) => {
setLogger(newLogger);
})
.catch(() => {});
}, [storage]);
}, [storage, config]);
return logger;
};