fix(folder): keep mobile sidebars closed on initial load
Prevent left and right sidebars from auto-opening on small screens during folder page initialization, regardless of persisted open state. Gate mobile sidebar sheets behind restored panel state to avoid initial sidebar pop-in.
This commit is contained in:
@@ -280,14 +280,22 @@ function MobileFolderWorkspaceShell({
|
||||
}: {
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
const { isOpen: sidebarOpen, toggle: toggleSidebar } = useSidebarContext()
|
||||
const { isOpen: auxOpen, toggle: toggleAux } = useAuxPanelContext()
|
||||
const {
|
||||
isOpen: sidebarOpen,
|
||||
restored: sidebarRestored,
|
||||
toggle: toggleSidebar,
|
||||
} = useSidebarContext()
|
||||
const {
|
||||
isOpen: auxOpen,
|
||||
restored: auxRestored,
|
||||
toggle: toggleAux,
|
||||
} = useAuxPanelContext()
|
||||
const { isOpen: terminalOpen, toggle: toggleTerminal } = useTerminalContext()
|
||||
|
||||
return (
|
||||
<div className="flex flex-1 min-h-0 overflow-hidden">
|
||||
{/* Sidebar Sheet (left) */}
|
||||
<Sheet open={sidebarOpen} onOpenChange={toggleSidebar}>
|
||||
<Sheet open={sidebarRestored && sidebarOpen} onOpenChange={toggleSidebar}>
|
||||
<SheetContent
|
||||
side="left"
|
||||
showCloseButton={false}
|
||||
@@ -304,7 +312,7 @@ function MobileFolderWorkspaceShell({
|
||||
</main>
|
||||
|
||||
{/* Aux panel Sheet (right) */}
|
||||
<Sheet open={auxOpen} onOpenChange={toggleAux}>
|
||||
<Sheet open={auxRestored && auxOpen} onOpenChange={toggleAux}>
|
||||
<SheetContent
|
||||
side="right"
|
||||
showCloseButton={false}
|
||||
|
||||
@@ -23,6 +23,7 @@ const DEFAULT_IS_OPEN = false
|
||||
|
||||
interface AuxPanelContextValue {
|
||||
isOpen: boolean
|
||||
restored: boolean
|
||||
width: number
|
||||
minWidth: number
|
||||
maxWidth: number
|
||||
@@ -94,9 +95,11 @@ export function AuxPanelProvider({
|
||||
|
||||
useEffect(() => {
|
||||
const stored = loadPersistedPanelState(storageKey)
|
||||
const isMobileViewport = window.innerWidth < 768
|
||||
const defaultOpen = isMobileViewport ? false : DEFAULT_IS_OPEN
|
||||
// Hydrate from localStorage after mount to keep SSR/CSR markup consistent.
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
setIsOpen(stored?.isOpen ?? DEFAULT_IS_OPEN)
|
||||
setIsOpen(isMobileViewport ? false : (stored?.isOpen ?? defaultOpen))
|
||||
setWidthState(clampWidth(stored?.width ?? DEFAULT_WIDTH))
|
||||
setRestored(true)
|
||||
}, [storageKey])
|
||||
@@ -109,6 +112,7 @@ export function AuxPanelProvider({
|
||||
const value = useMemo(
|
||||
() => ({
|
||||
isOpen,
|
||||
restored,
|
||||
width,
|
||||
minWidth: MIN_WIDTH,
|
||||
maxWidth: MAX_WIDTH,
|
||||
@@ -123,6 +127,7 @@ export function AuxPanelProvider({
|
||||
}),
|
||||
[
|
||||
isOpen,
|
||||
restored,
|
||||
width,
|
||||
activeTab,
|
||||
toggle,
|
||||
|
||||
@@ -21,6 +21,7 @@ const DEFAULT_IS_OPEN = true
|
||||
|
||||
interface SidebarContextValue {
|
||||
isOpen: boolean
|
||||
restored: boolean
|
||||
width: number
|
||||
minWidth: number
|
||||
maxWidth: number
|
||||
@@ -82,13 +83,14 @@ export function SidebarProvider({ children, folderId }: SidebarProviderProps) {
|
||||
const value = useMemo(
|
||||
() => ({
|
||||
isOpen,
|
||||
restored,
|
||||
width,
|
||||
minWidth: MIN_WIDTH,
|
||||
maxWidth: MAX_WIDTH,
|
||||
toggle,
|
||||
setWidth,
|
||||
}),
|
||||
[isOpen, width, toggle, setWidth]
|
||||
[isOpen, restored, width, toggle, setWidth]
|
||||
)
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user