Skip to content

Commit b5b1466

Browse files
committed
fix(web): track the sidebar sheet control through its lifecycle
1 parent 3ca7e2a commit b5b1466

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function readInitialThreadSidebarWidth(): number {
8383
function SidebarControl() {
8484
const usagePageOpen = useLocation({ select: (location) => location.pathname === "/usage" });
8585
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
86-
const { toggleSidebar } = useSidebar();
86+
const { toggleSidebar, isMobile, mobileSheetMounted } = useSidebar();
8787
const isSidebarVisible = useSidebarVisibility();
8888
const environmentIdentificationMode = useEnvironmentIdentificationMode();
8989
const stageBackdropVariant = useSidebarStageBackdropVariant(
@@ -140,7 +140,10 @@ function SidebarControl() {
140140
// off their edge and the titlebar reads symmetric.
141141
// The sheet owns its trigger until its closing transition unmounts it.
142142
<div
143-
className="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 in-[body:has([data-sidebar=sidebar][data-mobile=true])]:hidden"
143+
className={cn(
144+
"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",
145+
isMobile && mobileSheetMounted && "hidden",
146+
)}
144147
data-sidebar-control=""
145148
>
146149
<Tooltip>

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ type SidebarContextProps = {
3535
open: boolean;
3636
setOpen: (open: boolean) => void;
3737
openMobile: boolean;
38+
mobileSheetMounted: boolean;
39+
setMobileSheetElement: (element: HTMLDivElement | null) => void;
3840
setOpenMobile: (open: boolean) => void;
3941
isMobile: boolean;
4042
toggleSidebar: () => void;
@@ -107,6 +109,10 @@ function SidebarProvider({
107109
}) {
108110
const isMobile = useIsMobile();
109111
const [openMobile, setOpenMobile] = React.useState(false);
112+
const [mobileSheetMounted, setMobileSheetMounted] = React.useState(false);
113+
const setMobileSheetElement = React.useCallback((element: HTMLDivElement | null) => {
114+
setMobileSheetMounted(element !== null);
115+
}, []);
110116

111117
// This is the internal state of the sidebar.
112118
// We use openProp and setOpenProp for control from outside the component.
@@ -146,12 +152,23 @@ function SidebarProvider({
146152
isMobile,
147153
open,
148154
openMobile,
155+
mobileSheetMounted,
156+
setMobileSheetElement,
149157
setOpen,
150158
setOpenMobile,
151159
state,
152160
toggleSidebar,
153161
}),
154-
[state, open, setOpen, isMobile, openMobile, toggleSidebar],
162+
[
163+
state,
164+
open,
165+
setOpen,
166+
isMobile,
167+
openMobile,
168+
mobileSheetMounted,
169+
setMobileSheetElement,
170+
toggleSidebar,
171+
],
155172
);
156173

157174
return (
@@ -196,7 +213,7 @@ function Sidebar({
196213
collapsible?: "offcanvas" | "icon" | "none";
197214
resizable?: boolean | SidebarResizableOptions;
198215
}) {
199-
const { isMobile, state, openMobile, setOpenMobile } = useSidebar();
216+
const { isMobile, state, openMobile, setOpenMobile, setMobileSheetElement } = useSidebar();
200217
const resolvedResizable = React.useMemo<SidebarResolvedResizableOptions | null>(() => {
201218
if (isMobile || collapsible === "none" || !resizable) {
202219
return null;
@@ -238,6 +255,7 @@ function Sidebar({
238255
<SidebarInstanceContext value={instanceContextValue}>
239256
<Sheet onOpenChange={setOpenMobile} open={openMobile}>
240257
<SheetPopup
258+
ref={setMobileSheetElement}
241259
className={cn(
242260
"w-(--sidebar-width) max-w-none bg-sidebar surface-grain p-0 text-sidebar-foreground",
243261
className,

0 commit comments

Comments
 (0)