Skip to content

Commit 81dd7c4

Browse files
hunterbohmclaude
andcommitted
fix(web): thread shortcuts work in narrow windows with the sidebar closed
The narrow-window sidebar is a sheet that unmounted its content when closed. The thread list owns the Mod+1-9 and Mod+Shift+[/] handlers, so those shortcuts did nothing until the sheet was opened. Keep the sheet content mounted and track the sheet's finished transitions to hide the floating sidebar toggle while the sheet is on screen. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 121cd1c commit 81dd7c4

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

‎apps/web/src/components/AppSidebarLayout.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function readInitialThreadSidebarWidth(): number {
121121
function SidebarControl() {
122122
const usagePageOpen = useLocation({ select: (location) => location.pathname === "/usage" });
123123
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
124-
const { toggleSidebar, isMobile, mobileSheetMounted } = useSidebar();
124+
const { toggleSidebar, isMobile, mobileSheetShown } = useSidebar();
125125
const isSidebarVisible = useSidebarVisibility();
126126
const environmentIdentificationMode = useEnvironmentIdentificationMode();
127127
const stageBackdropVariant = useSidebarStageBackdropVariant(
@@ -174,7 +174,7 @@ function SidebarControl() {
174174
<div
175175
className={cn(
176176
"pointer-events-none fixed left-[var(--workspace-controls-left)] top-[var(--workspace-controls-top)] z-50 ml-px flex h-[var(--workspace-topbar-height)] items-center",
177-
isMobile && mobileSheetMounted && "hidden",
177+
isMobile && mobileSheetShown && "hidden",
178178
)}
179179
data-sidebar-control=""
180180
>

‎apps/web/src/components/ui/sidebar.tsx‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ type SidebarContextProps = {
3535
open: boolean;
3636
setOpen: (open: boolean) => void;
3737
openMobile: boolean;
38-
mobileSheetMounted: boolean;
39-
setMobileSheetElement: (element: HTMLDivElement | null) => void;
38+
mobileSheetShown: boolean;
39+
setMobileSheetOpened: (opened: boolean) => void;
4040
setOpenMobile: (open: boolean) => void;
4141
isMobile: boolean;
4242
toggleSidebar: () => void;
@@ -109,10 +109,11 @@ function SidebarProvider({
109109
}) {
110110
const isMobile = useIsMobile();
111111
const [openMobile, setOpenMobile] = React.useState(false);
112-
const [mobileSheetMounted, setMobileSheetMounted] = React.useState(false);
113-
const setMobileSheetElement = (element: HTMLDivElement | null) => {
114-
setMobileSheetMounted(element !== null);
115-
};
112+
// The last finished sheet transition, so a closing sheet still counts as shown.
113+
const [mobileSheetOpened, setMobileSheetOpened] = React.useState(false);
114+
// Widening the window mid-close unmounts the sheet before its transition reports.
115+
if (!isMobile && mobileSheetOpened) setMobileSheetOpened(false);
116+
const mobileSheetShown = openMobile || mobileSheetOpened;
116117

117118
const [_open, _setOpen] = React.useState(defaultOpen);
118119
const open = openProp ?? _open;
@@ -142,8 +143,8 @@ function SidebarProvider({
142143
isMobile,
143144
open,
144145
openMobile,
145-
mobileSheetMounted,
146-
setMobileSheetElement,
146+
mobileSheetShown,
147+
setMobileSheetOpened,
147148
setOpen,
148149
setOpenMobile,
149150
state,
@@ -214,7 +215,7 @@ function Sidebar({
214215
collapsible?: "offcanvas" | "icon" | "none";
215216
resizable?: boolean | SidebarResizableOptions;
216217
}) {
217-
const { isMobile, state, openMobile, setOpenMobile, setMobileSheetElement } = useSidebar();
218+
const { isMobile, state, openMobile, setOpenMobile, setMobileSheetOpened } = useSidebar();
218219
const desktopSidebarRef = React.useRef<HTMLDivElement>(null);
219220
const offcanvasCollapsed = !isMobile && collapsible === "offcanvas" && state === "collapsed";
220221

@@ -256,9 +257,14 @@ function Sidebar({
256257
if (isMobile) {
257258
return (
258259
<SidebarInstanceContext value={instanceContextValue}>
259-
<Sheet onOpenChange={setOpenMobile} open={openMobile}>
260+
<Sheet
261+
onOpenChange={setOpenMobile}
262+
onOpenChangeComplete={setMobileSheetOpened}
263+
open={openMobile}
264+
>
265+
{/* Kept mounted so the content's window shortcuts work while the sheet is closed. */}
260266
<SheetPopup
261-
ref={setMobileSheetElement}
267+
keepMounted
262268
className={cn(
263269
"w-(--sidebar-width) max-w-none bg-sidebar surface-grain p-0 text-sidebar-foreground",
264270
className,

0 commit comments

Comments
 (0)