@@ -2,6 +2,7 @@ import { useAtomValue } from "@effect/atom-react";
22import * as Schema from "effect/Schema" ;
33import {
44 useEffect ,
5+ useCallback ,
56 useState ,
67 useSyncExternalStore ,
78 type CSSProperties ,
@@ -23,7 +24,7 @@ import {
2324import LegacyThreadSidebar from "./LegacySidebar" ;
2425import ThreadSidebar from "./Sidebar" ;
2526import { SettingsSidebarNav } from "./settings/SettingsSidebarNav" ;
26- import { SidebarChromeHeader } from "./sidebar/SidebarChrome" ;
27+ import { SidebarChromeHeader , SidebarChromeIntrinsicWidthProbe } from "./sidebar/SidebarChrome" ;
2728import {
2829 resolveSidebarStageFocusRingOffsetClass ,
2930 useSidebarStageBackdropVariant ,
@@ -154,18 +155,26 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) {
154155 const isOnSettings = pathname === "/settings" || pathname . startsWith ( "/settings/" ) ;
155156 const isMacosDesktop = isElectron && isMacPlatform ( navigator . platform ) ;
156157 const [ sidebarWidth , setSidebarWidth ] = useState ( readInitialThreadSidebarWidth ) ;
158+ const [ sidebarMinimumWidth , setSidebarMinimumWidth ] = useState ( THREAD_SIDEBAR_MIN_WIDTH ) ;
159+ const updateSidebarMinimumWidth = useCallback ( ( intrinsicWidth : number ) => {
160+ setSidebarMinimumWidth ( Math . max ( THREAD_SIDEBAR_MIN_WIDTH , Math . ceil ( intrinsicWidth ) ) ) ;
161+ } , [ ] ) ;
157162 // Subscribed rather than read once: the clamp must track live window size,
158163 // and a clamped drag ends with an unchanged width, which skips the re-render
159164 // that would otherwise refresh a render-time snapshot.
160165 const viewportWidth = useSyncExternalStore ( subscribeToViewportWidth , readViewportWidth ) ;
161- const sidebarMaximumWidth = resolveThreadSidebarMaximumWidth ( viewportWidth ) ;
166+ const sidebarMaximumWidth = resolveThreadSidebarMaximumWidth ( viewportWidth , sidebarMinimumWidth ) ;
167+ const renderedSidebarWidth = Math . min (
168+ sidebarMaximumWidth ,
169+ Math . max ( sidebarMinimumWidth , sidebarWidth ) ,
170+ ) ;
162171 const resetSidebarWidth = ( ) => {
163172 try {
164173 removeLocalStorageItem ( THREAD_SIDEBAR_WIDTH_STORAGE_KEY ) ;
165174 } catch ( error ) {
166175 console . error ( "Could not clear persisted thread sidebar width." , error ) ;
167176 }
168- setSidebarWidth ( resolveInitialThreadSidebarWidth ( null , viewportWidth ) ) ;
177+ setSidebarWidth ( resolveInitialThreadSidebarWidth ( null , viewportWidth , sidebarMinimumWidth ) ) ;
169178 } ;
170179 const [ isWindowFullscreen , setIsWindowFullscreen ] = useState ( ( ) => {
171180 const getWindowFullscreenState = window . desktopBridge ?. getWindowFullscreenState ;
@@ -174,7 +183,7 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) {
174183 : false ;
175184 } ) ;
176185 const sidebarProviderStyle = {
177- "--sidebar-width" : `${ sidebarWidth } px` ,
186+ "--sidebar-width" : `${ renderedSidebarWidth } px` ,
178187 "--panel-animation-duration" : `${ panelAnimationDurationMs } ms` ,
179188 ...( isMacosDesktop && ! isWindowFullscreen
180189 ? { "--workspace-controls-left" : MACOS_TRAFFIC_LIGHTS_LEFT_INSET }
@@ -221,11 +230,14 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) {
221230 return (
222231 < PanelAnimationSuppressionProvider value = { panelAnimationsSuppressed } >
223232 < SidebarProvider
224- className = "h-dvh! min-h-0!"
233+ className = "relative h-dvh! min-h-0!"
225234 data-panel-animations = { routePanelAnimationsActive ? "true" : "false" }
226235 defaultOpen
227236 style = { sidebarProviderStyle }
228237 >
238+ { isMacosDesktop ? (
239+ < SidebarChromeIntrinsicWidthProbe onWidthChange = { updateSidebarMinimumWidth } />
240+ ) : null }
229241 < ProjectProjectionRetention />
230242 < Sidebar
231243 side = "left"
@@ -234,7 +246,7 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) {
234246 className = "border-r border-sidebar-border bg-sidebar text-sidebar-foreground"
235247 resizable = { {
236248 maxWidth : sidebarMaximumWidth ,
237- minWidth : THREAD_SIDEBAR_MIN_WIDTH ,
249+ minWidth : sidebarMinimumWidth ,
238250 shouldAcceptWidth : ( { currentWidth, nextWidth, wrapper } ) =>
239251 nextWidth <= currentWidth ||
240252 wrapper . clientWidth - nextWidth >= THREAD_MAIN_CONTENT_MIN_WIDTH ,
0 commit comments