diff --git a/static/js/chatRenderer.js b/static/js/chatRenderer.js index 63c56509b..e8aa9de5c 100644 --- a/static/js/chatRenderer.js +++ b/static/js/chatRenderer.js @@ -1005,7 +1005,12 @@ document.addEventListener('click', function(e) { // matching module via a dynamic import (avoids circular deps — // sessions.js itself imports chatRenderer.js). document.addEventListener('click', function(e) { - const a = e.target && e.target.closest && e.target.closest('a[href]'); + // Walk past Text nodes — clicking link text yields a Text node target + // whose .closest is undefined, so preventDefault never fires and the + // browser performs a default hash-navigation that resets the session. + let _t = e.target; + while (_t && _t.nodeType === Node.TEXT_NODE) _t = _t.parentElement; + const a = _t && _t.closest && _t.closest('a[href]'); if (!a) return; const href = a.getAttribute('href') || ''; if (!href.startsWith('#')) return; diff --git a/static/js/document.js b/static/js/document.js index 87ad2980c..ec9d79755 100644 --- a/static/js/document.js +++ b/static/js/document.js @@ -3728,6 +3728,9 @@ import * as Modals from './modalManager.js'; _minimizedDocId = null; Modals.unregister('doc-panel'); } + const container = document.getElementById('chat-container'); + if (!container) return; + isOpen = true; // Doc was opened last → it goes in front of the email windows (clears the // email-front flag; the doc/email z-index alternation lives in CSS). @@ -3735,9 +3738,6 @@ import * as Modals from './modalManager.js'; _ensureAgentMode(); _markDocVisibleState(_lastSessionId, 'open'); - const container = document.getElementById('chat-container'); - if (!container) return; - document.body.classList.add('doc-view'); // Sync toggle button state diff --git a/static/js/sessions.js b/static/js/sessions.js index dab25a107..23310d36c 100644 --- a/static/js/sessions.js +++ b/static/js/sessions.js @@ -1999,9 +1999,13 @@ export function initDragSort() { }); } -// Hash-based routing: navigate between sessions with browser back/forward +// Hash-based routing: navigate between sessions with browser back/forward. +// Skip entity-prefixed hashes (document-, note-, etc.) — those are handled +// by their own click handlers in chatRenderer.js and must not trigger +// session navigation (which would reset the active chat). window.addEventListener('hashchange', () => { const hashId = window.location.hash.replace('#', ''); + if (/^(document|note|image|email|event|task|skill|research)-/.test(hashId)) return; if (hashId && hashId !== currentSessionId) { const target = sessions.find(s => s.id === hashId && !s.archived); if (target) selectSession(hashId);