diff --git a/packages/web-shell/client/App.tsx b/packages/web-shell/client/App.tsx index 720c3699b00..c9471eead63 100644 --- a/packages/web-shell/client/App.tsx +++ b/packages/web-shell/client/App.tsx @@ -1153,23 +1153,50 @@ export function App({ if (!sidebarOptions.enabled) return undefined; const onKey = (e: KeyboardEvent) => { if (!isSidebarToggleShortcut(e)) return; + // The composer keeps the editor-convention behavior (VS Code toggles + // the sidebar while the editor is focused), but other editable targets + // — sidebar search, session rename, settings inputs — must not have + // the sidebar yanked around while the user is typing, matching the + // codebase's isEditableTarget convention. + const target = e.target as HTMLElement | null; + if ( + isEditableTarget(target) && + !target?.closest('[data-web-shell-composer-editor]') + ) { + return; + } e.preventDefault(); - if (window.matchMedia('(max-width: 760px)').matches) { - setMobileDrawerOpen((open) => { - if (open) setForceMobileDrawer(false); - return !open; - }); + // All state updates are dispatched sequentially outside the updater + // functions (React purity contract — mirrors the hamburger handler), + // which is why this effect re-binds on state changes: the listener + // closure must stay fresh. + if ( + forceMobileDrawer || + window.matchMedia('(max-width: 760px)').matches + ) { + // A forced drawer on a wide viewport still belongs to the drawer + // path: collapsing the rail underneath the overlay would look like + // a no-op to the user. + if (mobileDrawerOpen) { + setMobileDrawerOpen(false); + setForceMobileDrawer(false); + } else { + setMobileDrawerOpen(true); + } return; } - setSidebarCollapsed((collapsed) => { - const next = !collapsed; - writeSidebarCollapsed(next); - return next; - }); + const next = !sidebarCollapsed; + setSidebarCollapsed(next); + writeSidebarCollapsed(next); }; window.addEventListener('keydown', onKey); return () => window.removeEventListener('keydown', onKey); - }, [sidebarOptions.enabled]); + }, [ + sidebarOptions.enabled, + mobileDrawerOpen, + forceMobileDrawer, + sidebarCollapsed, + ]); const customization = useMemo( () => ({ composerTagIcons, diff --git a/packages/web-shell/client/hooks/useQueuedPrompts.ts b/packages/web-shell/client/hooks/useQueuedPrompts.ts index 0f6c7d23d77..e9f9947d12d 100644 --- a/packages/web-shell/client/hooks/useQueuedPrompts.ts +++ b/packages/web-shell/client/hooks/useQueuedPrompts.ts @@ -304,9 +304,14 @@ export function useQueuedPrompts({ const next = mergeRestoredPromptText(current, text); if (next !== current) { editorRef.current?.setText(next); - } - if (images && images.length > 0) { - editorRef.current?.restoreImages(images); + // Restore images only alongside a text change: restoreImages appends + // to the pasted-image list, so running it on a deduplicated restore + // (same prompt restored twice across reconnects/retries) would double + // the attachments while the text correctly stays single (#7134 + // review follow-up). + if (images && images.length > 0) { + editorRef.current?.restoreImages(images); + } } editorRef.current?.focus(); },