diff --git a/static/panels.js b/static/panels.js index 75f77605..1f7e3e9d 100644 --- a/static/panels.js +++ b/static/panels.js @@ -72,6 +72,10 @@ function syncAppTitlebar() { if (_renamingAppTitlebar) return; titleEl.textContent = mainText; + if (panel !== 'chat') { + const bot = typeof assistantDisplayName === 'function' ? assistantDisplayName() : ''; + document.title = bot ? mainText + ' \u2014 ' + bot : mainText; + } if (subEl) { if (subText) { subEl.textContent = subText; @@ -272,7 +276,8 @@ async function switchPanel(name, opts = {}) { if (overlay) overlay.classList.add('visible'); } _resyncChatSidebarAfterPanelSwitch(); - syncAppTitlebar(); + if (nextPanel === 'chat' && typeof syncTopbar === 'function') syncTopbar(); + else syncAppTitlebar(); return true; } diff --git a/tests/test_issue4039_panel_document_title.py b/tests/test_issue4039_panel_document_title.py new file mode 100644 index 00000000..97540b65 --- /dev/null +++ b/tests/test_issue4039_panel_document_title.py @@ -0,0 +1,31 @@ +"""Regression coverage for panel-driven document.title ownership (#4039).""" + +from __future__ import annotations + + +def _src(name: str) -> str: + with open(f"static/{name}", encoding="utf-8") as f: + return f.read() + + +def test_sync_app_titlebar_stamps_non_chat_document_title(): + src = _src("panels.js") + + assert "if (panel !== 'chat') {" in src + assert "const bot = typeof assistantDisplayName === 'function' ? assistantDisplayName() : '';" in src + assert "document.title = bot ? mainText + ' \\u2014 ' + bot : mainText;" in src + + +def test_switch_panel_restores_chat_title_via_sync_topbar(): + src = _src("panels.js") + + assert "if (nextPanel === 'chat' && typeof syncTopbar === 'function') syncTopbar();" in src + assert "else syncAppTitlebar();" in src + + +def test_chat_title_format_stays_owned_by_sync_topbar(): + panels_src = _src("panels.js") + ui_src = _src("ui.js") + + assert "document.title=sessionTitle+' \\u2014 '+assistantDisplayName();" in ui_src + assert "document.title=sessionTitle+' \\u2014 '+assistantDisplayName();" not in panels_src