Fix session list disappearing on page refresh
Frontend now fetches existing sessions from /api/sessions when SSE connects. Previously only listened for session_start events, causing sessions to disappear after page reload.
This commit is contained in:
parent
f9c521286b
commit
97cc975d55
1 changed files with 38 additions and 0 deletions
|
|
@ -1002,6 +1002,43 @@
|
|||
}
|
||||
}
|
||||
|
||||
async function fetchExistingSessions() {
|
||||
try {
|
||||
const res = await fetch('/api/sessions');
|
||||
if (!res.ok) {
|
||||
console.error('Failed to fetch existing sessions:', await res.text());
|
||||
return;
|
||||
}
|
||||
const sessions = await res.json();
|
||||
sessions.forEach(session => {
|
||||
state.sessions.set(session.id, {
|
||||
id: session.id,
|
||||
cwd: session.cwd,
|
||||
command: session.command,
|
||||
output: '',
|
||||
outputRenderedLength: 0,
|
||||
expanded: false,
|
||||
state: 'ready',
|
||||
prompts: 0,
|
||||
completions: 0,
|
||||
tools: 0,
|
||||
compressions: 0,
|
||||
thinking_seconds: 0,
|
||||
work_seconds: 0,
|
||||
mode: 'normal',
|
||||
model: null,
|
||||
idle_since: null,
|
||||
git_branch: null,
|
||||
git_files_json: null,
|
||||
autoScroll: true,
|
||||
});
|
||||
});
|
||||
renderSessions();
|
||||
} catch (error) {
|
||||
console.error('Error fetching existing sessions:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function connectSSE() {
|
||||
if (state.eventSource) {
|
||||
state.eventSource.close();
|
||||
|
|
@ -1016,6 +1053,7 @@
|
|||
clearTimeout(state.reconnectTimeout);
|
||||
state.reconnectTimeout = null;
|
||||
}
|
||||
fetchExistingSessions();
|
||||
});
|
||||
|
||||
es.addEventListener('error', () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue