@@ -111,17 +111,17 @@ const threadRef = {
111111
112112let settledAt = 0 ;
113113
114- function settle ( url : string , title : string , tabId = "tab_a" ) : void {
114+ function settle ( url : string , title : string , tabId = "tab_a" , ref = threadRef ) : void {
115115 settledAt += 1 ;
116116 const snapshot : PreviewSessionSnapshot = {
117- threadId : threadRef . threadId ,
117+ threadId : ref . threadId ,
118118 tabId,
119119 navStatus : { _tag : "Success" , url, title } ,
120120 canGoBack : false ,
121121 canGoForward : false ,
122122 updatedAt : new Date ( settledAt ) . toISOString ( ) ,
123123 } ;
124- applyPreviewServerSnapshot ( threadRef , snapshot ) ;
124+ applyPreviewServerSnapshot ( ref , snapshot ) ;
125125}
126126
127127function resetStores ( ) : ( ) => void {
@@ -162,6 +162,22 @@ describe("useBrowserHistoryStore", () => {
162162 expect ( useBrowserHistoryStore . getState ( ) . byProjectKey [ "proj-a" ] ?. [ 0 ] ?. title ) . toBe ( "New" ) ;
163163 } ) ;
164164
165+ it ( "keeps another thread's newer title when an unrelated tab settles" , ( ) => {
166+ const otherThreadRef = { ...threadRef , threadId : ThreadId . make ( "thread-2" ) } ;
167+ const store = useBrowserHistoryStore . getState ( ) ;
168+ store . registerThreadProject ( threadRef , "proj-a" ) ;
169+ store . registerThreadProject ( otherThreadRef , "proj-a" ) ;
170+ recordVisitForThread ( threadRef , "http://a.test/" , 1 ) ;
171+ settle ( "http://a.test/" , "Old" , "tab_a" , threadRef ) ;
172+ settle ( "http://a.test/" , "New" , "tab_a" , otherThreadRef ) ;
173+ settle ( "http://b.test/" , "Unrelated" , "tab_b" , threadRef ) ;
174+ expect (
175+ useBrowserHistoryStore
176+ . getState ( )
177+ . byProjectKey [ "proj-a" ] ?. find ( ( e ) => e . url === "http://a.test/" ) ?. title ,
178+ ) . toBe ( "New" ) ;
179+ } ) ;
180+
165181 it ( "sets a title against a settled url that differs from the stored one only by a trailing slash" , ( ) => {
166182 useBrowserHistoryStore . getState ( ) . registerThreadProject ( threadRef , "proj-a" ) ;
167183 recordVisitForThread ( threadRef , "http://a.test/community" , 1 ) ;
0 commit comments