@@ -663,8 +663,8 @@ const make = Effect.gen(function* () {
663663 return sources ;
664664 } ;
665665
666- // The replies in the rows the guest's stream opens with, so replies a fork inherits count too.
667- // Read again only when the thread changes, not for every image the page loads .
666+ // The replies in the rows the guest's stream opens with, so replies a fork inherits count too,
667+ // plus those read before. Read again only when the thread changes, not for every image.
668668 const repliesByThread = new Map <
669669 ThreadId ,
670670 {
@@ -681,12 +681,20 @@ const make = Effect.gen(function* () {
681681 rowLimit : SNAPSHOT_ROW_LIMIT ,
682682 userTurnLimit : SNAPSHOT_USER_TURN_LIMIT ,
683683 } ) ;
684- // Only replies with image syntax can show an image; the rest are not kept.
685- const replies = projection . visibleTurnItems . flatMap ( ( { item } ) =>
686- item . type === "assistant_message" && ( item . text . includes ( "![" ) || / < i m g / i. test ( item . text ) )
687- ? [ item ]
688- : [ ] ,
684+ // Replies already read stay: an open guest page keeps rows that slide out of the window.
685+ const kept = new Map (
686+ ( cached ?. replies ?? [ ] ) . map ( ( reply ) => [ `${ reply . threadId } \u0000${ reply . id } ` , reply ] ) ,
689687 ) ;
688+ for ( const { item } of projection . visibleTurnItems ) {
689+ // Only replies with image syntax can show an image; the rest are not kept.
690+ if (
691+ item . type === "assistant_message" &&
692+ ( item . text . includes ( "![" ) || / < i m g / i. test ( item . text ) )
693+ ) {
694+ kept . set ( `${ item . threadId } \u0000${ item . id } ` , item ) ;
695+ }
696+ }
697+ const replies = [ ...kept . values ( ) ] ;
690698 repliesByThread . delete ( threadId ) ;
691699 repliesByThread . set ( threadId , { sequence, replies } ) ;
692700 if ( repliesByThread . size > SHARED_THREAD_REPLIES_LIMIT ) {
0 commit comments