fix(terminal): 新建终端后侧边栏实时输出不更新

修复 TerminalPanel 中因空历史导致 _historyReady 始终为 false,
进而跳过所有 terminal_output 事件的问题。现在无论历史是否为空
都会标记加载完成;同时在历史加载期间暂存实时输出,避免首屏丢失。
This commit is contained in:
JOJO 2026-06-19 13:16:50 +08:00
parent 9e4b0bdb97
commit a6775598dc

View File

@ -182,7 +182,6 @@ function disposeTerminal() {
themeObserver = null;
term?.dispose();
term = null;
fitAddon = null;
}
// ---- ----
@ -332,11 +331,12 @@ async function initSocket() {
const s = data.session;
if (!s) return;
const delta = (data.data || '') as string;
// sessionLogs
// _historyReady false
sessionLogs.value[s] = (sessionLogs.value[s] || '') + delta;
if (s === activeSession.value && term && _historyReady.value[s]) {
console.log('[TerminalPanel] terminal_output WRITE:', s, 'len:', delta.length);
term.write(delta);
// sessionLogs
sessionLogs.value[s] = (sessionLogs.value[s] || '') + delta;
} else {
console.log('[TerminalPanel] terminal_output SKIP:', s, 'len:', delta.length, 'isActive:', s === activeSession.value, 'ready:', _historyReady.value[s]);
}
@ -389,17 +389,17 @@ async function initSocket() {
}
console.log('[TerminalPanel] handleHistory:', s, 'rawLen:', raw.length, 'payloadLen:', payload.length, 'isActive:', s === activeSession.value);
if (payload) {
payload = payload.replace(/\x1b\[1;32m➜.*?\x1b\[0m\n?/g, '');
const esc = String.fromCharCode(27);
payload = payload.replace(new RegExp(`${esc}\\[1;32m➜.*?${esc}\\[0m\\n?`, 'g'), '');
sessionLogs.value[s] = payload;
sessionHydrated.value = { ...sessionHydrated.value, [s]: true };
_historyReady.value = { ..._historyReady.value, [s]: true };
console.log('[TerminalPanel] handleHistory SAVED:', s, 'finalLen:', payload.length, 'calling render:', s === activeSession.value);
if (s === activeSession.value) {
renderSessionLog();
}
}
if (!sessionHydrated.value[s]) {
sessionHydrated.value = { ...sessionHydrated.value, [s]: true };
//
// _historyReady false seemingly
sessionHydrated.value = { ...sessionHydrated.value, [s]: true };
_historyReady.value = { ..._historyReady.value, [s]: true };
console.log('[TerminalPanel] handleHistory SAVED:', s, 'finalLen:', payload.length, 'calling render:', s === activeSession.value);
if (s === activeSession.value) {
renderSessionLog();
}
};