@@ -285,6 +285,9 @@ function WorkingDuration(props: { startedAt: string | null }) {
285285}
286286
287287const EMPTY_PROVIDER_ENTRIES : ReadonlyMap < string , ProviderInstanceEntry > = new Map ( ) ;
288+ // Collapsed shelves share one empty list so a route change alone does not
289+ // give the sidebar list a new identity.
290+ const EMPTY_THREADS : readonly EnvironmentThreadShell [ ] = [ ] ;
288291
289292function terminalProcessLabel ( count : number ) : string {
290293 return `${ count } terminal ${ count === 1 ? "process" : "processes" } running` ;
@@ -1535,7 +1538,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
15351538 data-thread-item
15361539 { ...sortableRootProps }
15371540 className = { cn (
1538- "list-none [content-visibility:auto] [contain-intrinsic-size:auto_34px]" ,
1541+ // Matches the h-9 row so unrendered rows never shift the list when they paint.
1542+ "list-none [content-visibility:auto] [contain-intrinsic-size:auto_36px]" ,
15391543 sortable ?. isDragging && "relative z-20" ,
15401544 ) }
15411545 >
@@ -1693,7 +1697,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
16931697 data-thread-item
16941698 { ...sortableRootProps }
16951699 className = { cn (
1696- "list-none py-0.5 [content-visibility:auto] [contain-intrinsic-size:auto_96px]" ,
1700+ // Matches the h-[4.875rem] content box; the py-0.5 padding is added on top.
1701+ "list-none py-0.5 [content-visibility:auto] [contain-intrinsic-size:auto_78px]" ,
16971702 sortable ?. isDragging && "relative z-20" ,
16981703 ) }
16991704 >
@@ -2664,12 +2669,12 @@ export default function Sidebar() {
26642669 ) ;
26652670 const renderedSettledThreads = useMemo ( ( ) => {
26662671 if ( settledShelfExpanded ) return visibleSettledThreads ;
2667- if ( routeThreadKey === null ) return [ ] ;
2672+ if ( routeThreadKey === null ) return EMPTY_THREADS ;
26682673 const routeThread = visibleSettledThreads . find (
26692674 ( thread ) =>
26702675 scopedThreadKey ( scopeThreadRef ( thread . environmentId , thread . id ) ) === routeThreadKey ,
26712676 ) ;
2672- return routeThread === undefined ? [ ] : [ routeThread ] ;
2677+ return routeThread === undefined ? EMPTY_THREADS : [ routeThread ] ;
26732678 } , [ routeThreadKey , settledShelfExpanded , visibleSettledThreads ] ) ;
26742679
26752680 // The snoozed shelf is collapsed by default: out of the way, never gone.
@@ -2690,12 +2695,12 @@ export default function Sidebar() {
26902695 // snoozed thread reached by route (deep link, open before snoozing
26912696 // elsewhere) keeps its row — with highlight and wake affordance — same
26922697 // exception the settled tail's "Show more" makes.
2693- if ( routeThreadKey === null ) return [ ] ;
2698+ if ( routeThreadKey === null ) return EMPTY_THREADS ;
26942699 const routeThread = snoozedThreads . find (
26952700 ( thread ) =>
26962701 scopedThreadKey ( scopeThreadRef ( thread . environmentId , thread . id ) ) === routeThreadKey ,
26972702 ) ;
2698- return routeThread === undefined ? [ ] : [ routeThread ] ;
2703+ return routeThread === undefined ? EMPTY_THREADS : [ routeThread ] ;
26992704 } , [ routeThreadKey , snoozedShelfExpanded , snoozedThreads ] ) ;
27002705
27012706 const orderedThreads = useMemo (
@@ -3282,15 +3287,32 @@ export default function Sidebar() {
32823287 }
32833288 } , [ cancelThreadDrag , dragState , sidebarListItems ] ) ;
32843289 const listMotionPaused = dragState !== null ;
3290+ // Every shell event rebuilds sidebarListItems, but rows only move when the
3291+ // rendered order or a row's section changes. Keying the motion pass on that
3292+ // keeps ordinary updates from forcing a layout read and animating rows
3293+ // whose position drifted for other reasons.
3294+ const sidebarListOrderKey = useMemo (
3295+ ( ) =>
3296+ sidebarListItems
3297+ . map ( ( item ) => ( item . kind === "thread" ? `${ item . key } :${ item . section } ` : item . marker ) )
3298+ . join ( "\0" ) ,
3299+ [ sidebarListItems ] ,
3300+ ) ;
3301+ const sidebarListHasRows = sidebarListItems . length + visibleDraftSessionCount > 0 ;
32853302 useLayoutEffect ( ( ) => {
32863303 // Drag release clears the baseline, so its commit cannot replay the
32873304 // sortable preview; rows glide from their released positions instead.
32883305 // Later thread actions can animate while writes settle.
32893306 // Draft navigation can reveal a frozen row without changing the draft count.
3290- listMotionRef . current ?. update (
3291- ! listMotionPaused && sidebarListItems . length + visibleDraftSessionCount > 0 ,
3292- ) ;
3293- } , [ listMotionPaused , routeDraftIdForRows , sidebarListItems , visibleDraftSessionCount ] ) ;
3307+ void sidebarListOrderKey ;
3308+ listMotionRef . current ?. update ( ! listMotionPaused && sidebarListHasRows ) ;
3309+ } , [
3310+ listMotionPaused ,
3311+ routeDraftIdForRows ,
3312+ sidebarListHasRows ,
3313+ sidebarListOrderKey ,
3314+ visibleDraftSessionCount ,
3315+ ] ) ;
32943316 const handleThreadDragOver = useCallback (
32953317 ( event : DragOverEvent ) => {
32963318 const target = event . over
0 commit comments