From 9a7d7a4379fd78c8005f5d975e57247c60599433 Mon Sep 17 00:00:00 2001 From: Catan <84828825+catan271@users.noreply.github.com> Date: Mon, 6 Jul 2026 15:16:23 +0700 Subject: [PATCH] fix(vscode): restore previous view when exiting settings (closes #1776) (closes #1848) --- .../ui/src/components/layout/VSCodeLayout.tsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/ui/src/components/layout/VSCodeLayout.tsx b/packages/ui/src/components/layout/VSCodeLayout.tsx index a2dd707d..10d44b28 100644 --- a/packages/ui/src/components/layout/VSCodeLayout.tsx +++ b/packages/ui/src/components/layout/VSCodeLayout.tsx @@ -108,6 +108,10 @@ export const VSCodeLayout: React.FC = () => { }, []); const [currentView, setCurrentView] = React.useState(() => (bootDraftOpen ? 'chat' : 'sessions')); + // Mirror currentView so the navigate event handler (registered once) can read the live value. + const currentViewRef = React.useRef(currentView); + // Snapshot of the view the user was on before opening Settings, so close restores it. + const viewBeforeSettingsRef = React.useRef(null); const [containerWidth, setContainerWidth] = React.useState(0); const [expandedSidebarWidth, setExpandedSidebarWidth] = React.useState(SESSIONS_SIDEBAR_WIDTH); const [isResizingExpandedSidebar, setIsResizingExpandedSidebar] = React.useState(false); @@ -185,6 +189,11 @@ export const VSCodeLayout: React.FC = () => { } }, [currentSessionId]); + // Keep currentViewRef in sync so the stable navigate handler reads the live view. + React.useEffect(() => { + currentViewRef.current = currentView; + }, [currentView]); + React.useEffect(() => { const vscodeApi = runtimeApis.vscode; if (!vscodeApi) { @@ -347,6 +356,9 @@ export const VSCodeLayout: React.FC = () => { const detail = (event as CustomEvent<{ view?: string }>).detail; const view = detail?.view; if (view === 'settings') { + if (currentViewRef.current !== 'settings') { + viewBeforeSettingsRef.current = currentViewRef.current; + } setCurrentView('settings'); } else if (view === 'chat') { setCurrentView('chat'); @@ -532,7 +544,11 @@ export const VSCodeLayout: React.FC = () => { // Settings view setCurrentView(usesExpandedLayout ? 'chat' : 'sessions')} + onClose={() => { + const previousView = viewBeforeSettingsRef.current; + viewBeforeSettingsRef.current = null; + setCurrentView(previousView ?? (usesExpandedLayout ? 'chat' : 'sessions')); + }} forceMobile={usesMobileLayout} />