@@ -761,14 +761,19 @@ function compactSidebarTimeLabel(label: string): string {
761761 return label . endsWith ( " ago" ) ? label . slice ( 0 , - 4 ) : label ;
762762}
763763
764- function threadTimeLabel ( thread : SidebarThreadSummary ) : string {
765- const timestamp = thread . latestUserMessageAt ?? thread . updatedAt ;
766- return compactSidebarTimeLabel ( formatRelativeTimeLabel ( timestamp ) ) ;
764+ // Subscribes to the minute tick itself, so only the label re-renders each
765+ // minute. The minute is passed as the clock so it is the formatter's input.
766+ function RelativeTimeLabel ( props : { timestamp : string | null } ) {
767+ const nowMinute = useNowMinute ( ) ;
768+ return props . timestamp === null
769+ ? null
770+ : compactSidebarTimeLabel (
771+ formatRelativeTimeLabel ( props . timestamp , Date . parse ( `${ nowMinute } :00.000Z` ) ) ,
772+ ) ;
767773}
768774
769- function settledTimeLabel ( thread : SidebarThreadSummary ) : string {
770- const timestamp = resolveSettledThreadTimestamp ( thread ) ;
771- return timestamp === null ? "" : compactSidebarTimeLabel ( formatRelativeTimeLabel ( timestamp ) ) ;
775+ function threadTimeTimestamp ( thread : SidebarThreadSummary ) : string {
776+ return thread . latestUserMessageAt ?? thread . updatedAt ;
772777}
773778
774779function JumpHintBadge ( props : { label : string } ) {
@@ -1055,18 +1060,25 @@ type SortableThreadRowBag = Pick<
10551060const SIDEBAR_SORTABLE_DRAG_DISABLED = { draggable : true } as const ;
10561061const SIDEBAR_SORTABLE_DRAG_ENABLED = { draggable : false } as const ;
10571062
1058- function SortableThreadRow ( props : {
1059- id : string ;
1060- disabled : boolean ;
1061- contextDrag : boolean ;
1062- environmentId : EnvironmentId ;
1063- children : ( bag : SortableThreadRowBag ) => ReactNode ;
1064- } ) {
1065- const canOperateThread = useEnvironmentScope ( props . environmentId , AuthOrchestrationOperateScope ) ;
1063+ // Takes the row's props rather than a render function: a closure from the
1064+ // sidebar body is new on every sidebar render, which rebuilt the bag and
1065+ // re-rendered every memoized row with it.
1066+ function SortableThreadRow (
1067+ props : Omit < SidebarThreadRowProps , "sortable" > & {
1068+ sortableId : string ;
1069+ sortableDisabled : boolean ;
1070+ contextDrag : boolean ;
1071+ } ,
1072+ ) {
1073+ const { sortableId, sortableDisabled, contextDrag, ...rowProps } = props ;
1074+ const canOperateThread = useEnvironmentScope (
1075+ rowProps . thread . environmentId ,
1076+ AuthOrchestrationOperateScope ,
1077+ ) ;
10661078 const { listeners, setNodeRef, transform, transition, isDragging } = useSortable ( {
1067- id : props . id ,
1079+ id : sortableId ,
10681080 disabled :
1069- props . disabled || ! canOperateThread
1081+ sortableDisabled || ! canOperateThread
10701082 ? SIDEBAR_SORTABLE_DRAG_DISABLED
10711083 : SIDEBAR_SORTABLE_DRAG_ENABLED ,
10721084 animateLayoutChanges : animateSidebarLayoutChanges ,
@@ -1076,11 +1088,12 @@ function SortableThreadRow(props: {
10761088 const bag = {
10771089 listeners,
10781090 setNodeRef,
1079- transform : props . contextDrag ? null : transform ,
1080- transition : props . contextDrag && isDragging ? "transform 150ms ease-out" : transition ,
1081- isDragging : isDragging && ! props . contextDrag ,
1091+ transform : contextDrag ? null : transform ,
1092+ transition : contextDrag && isDragging ? "transform 150ms ease-out" : transition ,
1093+ isDragging : isDragging && ! contextDrag ,
10821094 } ;
1083- return props . children ( bag ) ;
1095+ // Keyed by variant so a card/slim switch remounts the row.
1096+ return < SidebarThreadRow key = { rowProps . variant } { ...rowProps } sortable = { bag } /> ;
10841097}
10851098
10861099const draftSurfaceClassName = "bg-warning/4 hover:bg-warning/8" ;
@@ -1449,7 +1462,7 @@ const dropVerbBadge: Record<SidebarDropVerb, ReactNode> = {
14491462 ) ,
14501463} ;
14511464
1452- const SidebarThreadRow = memo ( function SidebarThreadRow ( props : {
1465+ type SidebarThreadRowProps = {
14531466 thread : SidebarThreadSummary ;
14541467 variant : "card" | "slim" ;
14551468 variantAction : SidebarSweepAction ;
@@ -1495,7 +1508,9 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
14951508 onUnpin : ( threadRef : ScopedThreadRef ) => void ;
14961509 onAcknowledgeWoke : ( threadRef : ScopedThreadRef , visitedAt : string ) => void ;
14971510 onFileDropThreads ?: ( ( threadRef : ScopedThreadRef , files : File [ ] ) => void ) | undefined ;
1498- } ) {
1511+ } ;
1512+
1513+ const SidebarThreadRow = memo ( function SidebarThreadRow ( props : SidebarThreadRowProps ) {
14991514 const {
15001515 isRenaming,
15011516 onCancelRename,
@@ -2071,9 +2086,13 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
20712086 </ Tooltip >
20722087 ) : (
20732088 < span className = "text-xs" >
2074- { variantAction === "unsettle"
2075- ? settledTimeLabel ( thread )
2076- : threadTimeLabel ( thread ) }
2089+ < RelativeTimeLabel
2090+ timestamp = {
2091+ variantAction === "unsettle"
2092+ ? resolveSettledThreadTimestamp ( thread )
2093+ : threadTimeTimestamp ( thread )
2094+ }
2095+ />
20772096 </ span >
20782097 ) }
20792098 </ span >
@@ -2263,7 +2282,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
22632282 </ span >
22642283 )
22652284 ) : (
2266- threadTimeLabel ( thread )
2285+ < RelativeTimeLabel timestamp = { threadTimeTimestamp ( thread ) } />
22672286 ) }
22682287 </ span >
22692288 { props . settlementSupported || showSnoozeButton || hasUnsentDraft ? (
@@ -2547,7 +2566,7 @@ const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props: {
25472566 />
25482567 </ span >
25492568 < span className = "w-8 shrink-0 text-right text-xs text-muted-foreground/55 tabular-nums" >
2550- { threadTimeLabel ( thread ) }
2569+ < RelativeTimeLabel timestamp = { threadTimeTimestamp ( thread ) } />
25512570 </ span >
25522571 </ span >
25532572 { props . searchMatch ? (
@@ -4681,10 +4700,9 @@ export default function Sidebar() {
46814700 ) }
46824701 >
46834702 { ( ( ) => {
4684- const renderThreadRowInner = (
4703+ const renderThreadRow = (
46854704 thread : EnvironmentThreadShell ,
46864705 section : SidebarSection ,
4687- sortable ?: SortableThreadRowBag ,
46884706 ) => {
46894707 const threadKey = scopedThreadKey (
46904708 scopeThreadRef ( thread . environmentId , thread . id ) ,
@@ -4693,8 +4711,16 @@ export default function Sidebar() {
46934711 section === "active" || section === "pinned" || section === "working" ;
46944712 const rowVariant = isCard ? "card" : "slim" ;
46954713 return (
4696- < SidebarThreadRow
4697- key = { `${ threadKey } :${ rowVariant } ` }
4714+ < SortableThreadRow
4715+ key = { threadKey }
4716+ sortableId = { threadKey }
4717+ contextDrag = { isContextDrag }
4718+ sortableDisabled = {
4719+ renamingThreadKey === threadKey ||
4720+ section === "working" ||
4721+ ! draggableThreadKeys . has ( threadKey ) ||
4722+ optimisticDrop !== null
4723+ }
46984724 thread = { thread }
46994725 variant = { rowVariant }
47004726 variantAction = {
@@ -4717,7 +4743,6 @@ export default function Sidebar() {
47174743 . threadPinning === true
47184744 }
47194745 isPinned = { thread . pinnedAt != null }
4720- sortable = { sortable }
47214746 dropVerb = {
47224747 dragState ?. activeKey === threadKey
47234748 ? resolveSidebarDropVerb ( dragState . activeSection , dragTargetSection )
@@ -4784,30 +4809,6 @@ export default function Sidebar() {
47844809 />
47854810 ) ;
47864811 } ;
4787- const renderThreadRow = (
4788- thread : EnvironmentThreadShell ,
4789- section : SidebarSection ,
4790- ) => {
4791- const threadKey = scopedThreadKey (
4792- scopeThreadRef ( thread . environmentId , thread . id ) ,
4793- ) ;
4794- return (
4795- < SortableThreadRow
4796- key = { threadKey }
4797- id = { threadKey }
4798- contextDrag = { isContextDrag }
4799- environmentId = { thread . environmentId }
4800- disabled = {
4801- renamingThreadKey === threadKey ||
4802- section === "working" ||
4803- ! draggableThreadKeys . has ( threadKey ) ||
4804- optimisticDrop !== null
4805- }
4806- >
4807- { ( bag ) => renderThreadRowInner ( thread , section , bag ) }
4808- </ SortableThreadRow >
4809- ) ;
4810- } ;
48114812 const from = isContextDrag ? null : ( dragState ?. activeSection ?? null ) ;
48124813 const items : ReactNode [ ] = [
48134814 < SidebarDraftBlock
0 commit comments