@@ -292,20 +292,27 @@ export function useFaviconForThreadUrl(threadRef: ScopedThreadRef, url: string):
292292 ? new URL ( preparedConnection . value . httpBaseUrl ) . hostname
293293 : null ;
294294 const threadKey = scopedThreadKey ( threadRef ) ;
295- return useBrowserFaviconStore (
296- ( state ) =>
297- lookupFavicon ( state . byKey , projectRef , url , environmentHostname ) ??
298- lookupPendingFavicon ( state . pendingByThreadKey [ threadKey ] , url ) ,
295+ return useBrowserFaviconStore ( ( state ) =>
296+ lookupFaviconForThread ( state , threadKey , projectRef , url , environmentHostname ) ,
299297 ) ;
300298}
301299
302- /** A capture waiting for its thread's project still shows on that thread. */
303- function lookupPendingFavicon (
304- pending : PendingFaviconsByOrigin | undefined ,
300+ /**
301+ * A capture waiting for its thread's project still shows on that thread, and wins
302+ * over an older stored capture for the same origin.
303+ */
304+ export function lookupFaviconForThread (
305+ state : Pick < BrowserFaviconStoreState , "byKey" | "pendingByThreadKey" > ,
306+ threadKey : string ,
307+ projectRef : ScopedProjectRef | null ,
305308 url : string ,
309+ environmentHostname : string | null ,
306310) : string | null {
307- const originKey = pending ? pendingOriginKey ( url ) : null ;
308- return originKey ? ( pending ?. [ originKey ] ?. dataUrl ?? null ) : null ;
311+ const stored = lookupFaviconEntry ( state . byKey , projectRef , url , environmentHostname ) ;
312+ const originKey = pendingOriginKey ( url ) ;
313+ const pending = originKey ? state . pendingByThreadKey [ threadKey ] ?. [ originKey ] : undefined ;
314+ if ( pending && ( ! stored || pending . capturedAt > stored . capturedAt ) ) return pending . dataUrl ;
315+ return stored ?. dataUrl ?? null ;
309316}
310317
311318export function lookupFavicon (
@@ -314,17 +321,26 @@ export function lookupFavicon(
314321 url : string ,
315322 environmentHostname : string | null ,
316323) : string | null {
324+ return lookupFaviconEntry ( byKey , projectRef , url , environmentHostname ) ?. dataUrl ?? null ;
325+ }
326+
327+ function lookupFaviconEntry (
328+ byKey : Record < string , BrowserFaviconEntry > ,
329+ projectRef : ScopedProjectRef | null ,
330+ url : string ,
331+ environmentHostname : string | null ,
332+ ) : BrowserFaviconEntry | null {
317333 const key = projectRef
318334 ? faviconKey ( scopedProjectKey ( projectRef ) , url , environmentHostname )
319335 : null ;
320336 if ( ! key ) return null ;
321337 const direct = byKey [ key ] ;
322- if ( direct ) return direct . dataUrl ;
338+ if ( direct ) return direct ;
323339 try {
324340 const requestedHost = normalizeHostname ( new URL ( url ) . hostname ) ;
325341 const localKey = faviconKey ( scopedProjectKey ( projectRef ! ) , url , requestedHost ) ;
326342 const localEntry = localKey ? byKey [ localKey ] : null ;
327- return localEntry ?. aliases ?. includes ( requestedHost ) ? localEntry . dataUrl : null ;
343+ return localEntry ?. aliases ?. includes ( requestedHost ) ? localEntry : null ;
328344 } catch {
329345 return null ;
330346 }
0 commit comments