diff --git a/packages/ui/src/components/layout/ContextPanel.tsx b/packages/ui/src/components/layout/ContextPanel.tsx index a8d5b159..6b173209 100644 --- a/packages/ui/src/components/layout/ContextPanel.tsx +++ b/packages/ui/src/components/layout/ContextPanel.tsx @@ -45,6 +45,7 @@ import { invokeDesktopCommand } from '@/lib/desktopNative'; import { EMBEDDED_RUNTIME_BOOTSTRAP_REQUEST, EMBEDDED_RUNTIME_BOOTSTRAP_RESPONSE, + getActiveEmbeddedSessionChatTab, getOrCreateEmbeddedSessionChatURL, type EmbeddedSessionChatURLCacheEntry, type EmbeddedSessionRuntimeBootstrap, @@ -2483,8 +2484,13 @@ export const ContextPanel: React.FC = () => { }, [activeTab, directoryKey, setSelectedFilePath]); - const activeChatTabID = activeTab?.mode === 'chat' ? activeTab.id : null; - const activeChatSessionID = activeTab?.mode === 'chat' ? getSessionIDFromDedupeKey(activeTab.dedupeKey) : null; + const chatTabs = React.useMemo( + () => tabs.filter((tab) => tab.mode === 'chat'), + [tabs], + ); + const activeChatTabID = isOpen && activeTab?.mode === 'chat' ? activeTab.id : null; + const activeChatSessionID = isOpen && activeTab?.mode === 'chat' ? getSessionIDFromDedupeKey(activeTab.dedupeKey) : null; + const activeChatTab = getActiveEmbeddedSessionChatTab(chatTabs, activeChatTabID); React.useEffect(() => { if (!isOpen || !directoryKey || !activeChatSessionID || typeof window === 'undefined') { @@ -2525,6 +2531,10 @@ export const ContextPanel: React.FC = () => { }); }, [currentTheme, darkThemeId, directoryKey, lightThemeId, themeMode]); + const activeChatSrc = activeChatTab && activeChatSessionID + ? getEmbeddedChatSrc(activeChatTab.id, activeChatSessionID, activeChatTab.readOnly) + : null; + React.useEffect(() => { const liveTabIDs = new Set(tabs.map((tab) => tab.id)); for (const tabID of chatFrameSrcByTabIDRef.current.keys()) { @@ -2721,10 +2731,6 @@ export const ContextPanel: React.FC = () => { ); - const chatTabs = React.useMemo( - () => tabs.filter((tab) => tab.mode === 'chat'), - [tabs], - ); const browserTabs = React.useMemo( () => tabs.filter((tab) => tab.mode === 'browser'), [tabs], @@ -2934,41 +2940,26 @@ export const ContextPanel: React.FC = () => { ) : null} - {chatTabs.map((tab) => { - const sessionID = getSessionIDFromDedupeKey(tab.dedupeKey); - if (!sessionID) { - return null; - } - - const src = getEmbeddedChatSrc(tab.id, sessionID, tab.readOnly); - if (!src) { - return null; - } - - return ( -