@@ -40,8 +40,20 @@ function revalidateInBackground(
4040 fromShare : string | undefined ,
4141 served : ConversationData
4242) {
43- void fetchConversation ( client , id , fromShare )
44- . then ( ( fresh ) => {
43+ void client
44+ . conversations ( { id } )
45+ . get ( { query : { fromShare } } )
46+ . then ( ( response ) => {
47+ // The conversation is gone or this session can no longer read it
48+ // (deleted in another tab, revoked access, expired session): drop the
49+ // entry and re-run the load so the page takes its real error path
50+ // (redirect home) instead of keeping the stale view on screen.
51+ if ( response . status === 401 || response . status === 403 || response . status === 404 ) {
52+ invalidateCachedConversation ( id ) ;
53+ return safeInvalidate ( UrlDependency . Conversation ) ;
54+ }
55+ // Throws on remaining errors (5xx etc.), handled as transient below.
56+ const fresh = handleResponse ( response ) as ConversationData ;
4557 if ( conversationFingerprint ( fresh ) === conversationFingerprint ( served ) ) return ;
4658 setCachedConversation ( id , fresh ) ;
4759 // safeInvalidate, not invalidate: a raw invalidate() fired from this
@@ -50,11 +62,10 @@ function revalidateInBackground(
5062 return safeInvalidate ( UrlDependency . Conversation ) ;
5163 } )
5264 . catch ( ( ) => {
53- // Could be a transient network failure just as well as a deleted or
54- // inaccessible conversation — we cannot tell them apart here. Only
55- // drop the cache entry; the next real navigation refetches and takes
56- // the genuine error path. Forcing a reload here would bounce the user
57- // to the homepage on a mere network blip.
65+ // Transient failure (network blip, server error): only drop the cache
66+ // entry; the next real navigation refetches and takes the genuine
67+ // error path. Forcing a reload here would bounce the user to the
68+ // homepage on a mere network hiccup.
5869 invalidateCachedConversation ( id ) ;
5970 } ) ;
6071}
0 commit comments