@@ -85,8 +85,10 @@ export default function Logs() {
8585 const [ selectedLog , setSelectedLog ] = useState < WorkflowLog | null > ( null )
8686 const [ selectedLogIndex , setSelectedLogIndex ] = useState < number > ( - 1 )
8787 const [ isSidebarOpen , setIsSidebarOpen ] = useState ( false )
88+ const [ isDetailsLoading , setIsDetailsLoading ] = useState ( false )
8889 const detailsCacheRef = useRef < Map < string , any > > ( new Map ( ) )
8990 const detailsAbortRef = useRef < AbortController | null > ( null )
91+ const currentDetailsIdRef = useRef < string | null > ( null )
9092 const selectedRowRef = useRef < HTMLTableRowElement | null > ( null )
9193 const loaderRef = useRef < HTMLDivElement > ( null )
9294 const scrollContainerRef = useRef < HTMLDivElement > ( null )
@@ -118,6 +120,7 @@ export default function Logs() {
118120 const index = logs . findIndex ( ( l ) => l . id === log . id )
119121 setSelectedLogIndex ( index )
120122 setIsSidebarOpen ( true )
123+ setIsDetailsLoading ( true )
121124
122125 // Fetch details for current, previous, and next concurrently with cache
123126 const currentId = log . id
@@ -134,24 +137,26 @@ export default function Logs() {
134137 }
135138 const controller = new AbortController ( )
136139 detailsAbortRef . current = controller
140+ currentDetailsIdRef . current = currentId
137141
138142 const idsToFetch : Array < { id : string ; merge : boolean } > = [ ]
139- if ( currentId && ! detailsCacheRef . current . has ( currentId ) )
140- idsToFetch . push ( { id : currentId , merge : true } )
143+ const cachedCurrent = currentId ? detailsCacheRef . current . get ( currentId ) : undefined
144+ if ( currentId && ! cachedCurrent ) idsToFetch . push ( { id : currentId , merge : true } )
141145 if ( prevId && ! detailsCacheRef . current . has ( prevId ) )
142146 idsToFetch . push ( { id : prevId , merge : false } )
143147 if ( nextId && ! detailsCacheRef . current . has ( nextId ) )
144148 idsToFetch . push ( { id : nextId , merge : false } )
145149
146- if ( idsToFetch . length === 0 ) {
147- const cached = detailsCacheRef . current . get ( currentId )
148- if ( cached ) {
149- setSelectedLog ( ( prev ) =>
150- prev && prev . id === currentId ? ( { ...( prev as any ) , ...( cached as any ) } as any ) : prev
151- )
152- }
153- return
150+ // Merge cached current immediately
151+ if ( cachedCurrent ) {
152+ setSelectedLog ( ( prev ) =>
153+ prev && prev . id === currentId
154+ ? ( { ...( prev as any ) , ...( cachedCurrent as any ) } as any )
155+ : prev
156+ )
157+ setIsDetailsLoading ( false )
154158 }
159+ if ( idsToFetch . length === 0 ) return
155160
156161 Promise . all (
157162 idsToFetch . map ( async ( { id, merge } ) => {
@@ -166,6 +171,7 @@ export default function Logs() {
166171 setSelectedLog ( ( prev ) =>
167172 prev && prev . id === id ? ( { ...( prev as any ) , ...( detailed as any ) } as any ) : prev
168173 )
174+ if ( currentDetailsIdRef . current === id ) setIsDetailsLoading ( false )
169175 }
170176 }
171177 } catch ( e : any ) {
0 commit comments