Fix two critical session issues in Claude Code IDE

Issue 1: Sessions history not showing in left sidebar
- Converted loadChatHistoryOnLoad IIFE to named loadChatHistory() function
- Added refresh calls in loadSessionMessages() after loading messages
- Added guard to skip refresh if showing "Loading session..." state
- Sidebar now properly shows all active sessions after attachment

Issue 2: New chat session button fails with 'Failed to create session'
- Changed startNewChat() to call loadChatHistory() instead of loadChatView()
- Prevents triggering URL-based attachment logic that was causing confusion
- Sidebar now refreshes correctly without getting stuck in loading state

Also updated cache-bust version to force browser reload.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
uroma
2026-01-22 11:46:31 +00:00
Unverified
parent 9ff98e975b
commit 3067c6bc24
4 changed files with 1031 additions and 127 deletions

View File

@@ -47,7 +47,8 @@ function enhanceChatInput() {
// ============================================
// Auto-load chat history when page loads
(async function loadChatHistoryOnLoad() {
// Make this a named function so it can be called to refresh the sidebar
async function loadChatHistory() {
try {
const res = await fetch('/claude/api/claude/sessions');
const data = await res.json();
@@ -55,6 +56,13 @@ function enhanceChatInput() {
const historyList = document.getElementById('chat-history-list');
if (!historyList) return;
// Skip update if we're showing "Loading session..." to avoid conflicts
// with attachToSession's loading state
if (historyList.textContent.includes('Loading session')) {
console.log('[loadChatHistory] Skipping update - showing loading state');
return;
}
// Combine active and historical sessions
const allSessions = [
...(data.active || []).map(s => ({...s, status: 'active'})),
@@ -97,9 +105,17 @@ function enhanceChatInput() {
}).join('');
} catch (error) {
console.error('[loadChatHistoryOnLoad] Error loading chat history:', error);
console.error('[loadChatHistory] Error loading chat history:', error);
}
})();
}
// Auto-load chat history when page loads
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', loadChatHistory);
} else {
// DOM already loaded, load immediately
loadChatHistory();
}
// Resume historical session
async function resumeSession(sessionId) {