@@ -290,6 +290,9 @@ function WorkingDuration(props: { startedAt: string | null }) {
290290}
291291
292292const EMPTY_PROVIDER_ENTRIES : ReadonlyMap < string , ProviderInstanceEntry > = new Map ( ) ;
293+ // Collapsed shelves share one empty list so a route change alone does not
294+ // give the sidebar list a new identity.
295+ const EMPTY_THREADS : readonly EnvironmentThreadShell [ ] = [ ] ;
293296
294297function terminalProcessLabel ( count : number ) : string {
295298 return `${ count } terminal ${ count === 1 ? "process" : "processes" } running` ;
@@ -1572,7 +1575,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
15721575 { ...sortableRootProps }
15731576 { ...( fileDropHandlers ?? { } ) }
15741577 className = { cn (
1575- "list-none [content-visibility:auto] [contain-intrinsic-size:auto_34px]" ,
1578+ // Matches the h-9 row so unrendered rows never shift the list when they paint.
1579+ "list-none [content-visibility:auto] [contain-intrinsic-size:auto_36px]" ,
15761580 sortable ?. isDragging && "relative z-20" ,
15771581 ) }
15781582 >
@@ -1731,7 +1735,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
17311735 { ...sortableRootProps }
17321736 { ...( fileDropHandlers ?? { } ) }
17331737 className = { cn (
1734- "list-none py-0.5 [content-visibility:auto] [contain-intrinsic-size:auto_96px]" ,
1738+ // Matches the h-[4.875rem] content box; the py-0.5 padding is added on top.
1739+ "list-none py-0.5 [content-visibility:auto] [contain-intrinsic-size:auto_78px]" ,
17351740 sortable ?. isDragging && "relative z-20" ,
17361741 ) }
17371742 >
@@ -2702,12 +2707,12 @@ export default function Sidebar() {
27022707 ) ;
27032708 const renderedSettledThreads = useMemo ( ( ) => {
27042709 if ( settledShelfExpanded ) return visibleSettledThreads ;
2705- if ( routeThreadKey === null ) return [ ] ;
2710+ if ( routeThreadKey === null ) return EMPTY_THREADS ;
27062711 const routeThread = visibleSettledThreads . find (
27072712 ( thread ) =>
27082713 scopedThreadKey ( scopeThreadRef ( thread . environmentId , thread . id ) ) === routeThreadKey ,
27092714 ) ;
2710- return routeThread === undefined ? [ ] : [ routeThread ] ;
2715+ return routeThread === undefined ? EMPTY_THREADS : [ routeThread ] ;
27112716 } , [ routeThreadKey , settledShelfExpanded , visibleSettledThreads ] ) ;
27122717
27132718 // The snoozed shelf is collapsed by default: out of the way, never gone.
@@ -2728,12 +2733,12 @@ export default function Sidebar() {
27282733 // snoozed thread reached by route (deep link, open before snoozing
27292734 // elsewhere) keeps its row — with highlight and wake affordance — same
27302735 // exception the settled tail's "Show more" makes.
2731- if ( routeThreadKey === null ) return [ ] ;
2736+ if ( routeThreadKey === null ) return EMPTY_THREADS ;
27322737 const routeThread = snoozedThreads . find (
27332738 ( thread ) =>
27342739 scopedThreadKey ( scopeThreadRef ( thread . environmentId , thread . id ) ) === routeThreadKey ,
27352740 ) ;
2736- return routeThread === undefined ? [ ] : [ routeThread ] ;
2741+ return routeThread === undefined ? EMPTY_THREADS : [ routeThread ] ;
27372742 } , [ routeThreadKey , snoozedShelfExpanded , snoozedThreads ] ) ;
27382743
27392744 const orderedThreads = useMemo (
@@ -3362,15 +3367,32 @@ export default function Sidebar() {
33623367 }
33633368 } , [ cancelThreadDrag , dragState , sidebarListItems ] ) ;
33643369 const listMotionPaused = dragState !== null ;
3370+ // Every shell event rebuilds sidebarListItems, but rows only move when the
3371+ // rendered order or a row's section changes. Keying the motion pass on that
3372+ // keeps ordinary updates from forcing a layout read and animating rows
3373+ // whose position drifted for other reasons.
3374+ const sidebarListOrderKey = useMemo (
3375+ ( ) =>
3376+ sidebarListItems
3377+ . map ( ( item ) => ( item . kind === "thread" ? `${ item . key } :${ item . section } ` : item . marker ) )
3378+ . join ( "\0" ) ,
3379+ [ sidebarListItems ] ,
3380+ ) ;
3381+ const sidebarListHasRows = sidebarListItems . length + visibleDraftSessionCount > 0 ;
33653382 useLayoutEffect ( ( ) => {
33663383 // Drag release clears the baseline, so its commit cannot replay the
33673384 // sortable preview; rows glide from their released positions instead.
33683385 // Later thread actions can animate while writes settle.
33693386 // Draft navigation can reveal a frozen row without changing the draft count.
3370- listMotionRef . current ?. update (
3371- ! listMotionPaused && sidebarListItems . length + visibleDraftSessionCount > 0 ,
3372- ) ;
3373- } , [ listMotionPaused , routeDraftIdForRows , sidebarListItems , visibleDraftSessionCount ] ) ;
3387+ void sidebarListOrderKey ;
3388+ listMotionRef . current ?. update ( ! listMotionPaused && sidebarListHasRows ) ;
3389+ } , [
3390+ listMotionPaused ,
3391+ routeDraftIdForRows ,
3392+ sidebarListHasRows ,
3393+ sidebarListOrderKey ,
3394+ visibleDraftSessionCount ,
3395+ ] ) ;
33743396 const handleThreadDragOver = useCallback (
33753397 ( event : DragOverEvent ) => {
33763398 const target = event . over
0 commit comments