@@ -102,11 +102,14 @@ const RESIZE_HANDLES: ReadonlyArray<{
102102 { direction : "southeast" , className : "-bottom-2 -right-2 size-4 cursor-nwse-resize" } ,
103103] ;
104104
105- // What the streams report about their source. It lives outside the player so
106- // the chat canvas lays out the frame from the same source size the player uses.
107- const useStreamedSourceSizes = create < {
108- readonly viewports : Record < string , PreviewStreamViewport > ;
109- } > ( ( ) => ( { viewports : { } } ) ) ;
105+ // What the stream reports about its source. It lives outside the player so the
106+ // chat canvas lays out the frame from the same source size the player uses. One
107+ // slot is enough, since only the shown thread renders a player, and it keeps the
108+ // store from collecting an entry for every tab a session ever streamed.
109+ const useStreamedSourceSize = create < {
110+ readonly key : string ;
111+ readonly viewport : PreviewStreamViewport ;
112+ } | null > ( ( ) => null ) ;
110113
111114const NO_DEVICE_SCREEN_ATOM = Atom . make < DeviceScreenSize | null > ( null ) . pipe (
112115 Atom . withLabel ( "device-stream-screen:none" ) ,
@@ -140,11 +143,12 @@ function useBrowserMiniPlayerSource(threadRef: ScopedThreadRef | null, tabId: st
140143 threadRef !== null &&
141144 snapshot ?. runtime === "server" &&
142145 ! rendersServerTabNatively ( threadRef . environmentId , primaryEnvironmentId , snapshot ) ;
143- const streamViewport = useStreamedSourceSizes ( ( state ) =>
144- threadRef && tabId !== null
145- ? ( state . viewports [
146- streamedSourceKey ( threadRef , previewMiniPlayerSourceKey ( browserMiniPlayerSource ( tabId ) ) )
147- ] ?? null )
146+ const streamViewport = useStreamedSourceSize ( ( state ) =>
147+ threadRef &&
148+ tabId !== null &&
149+ state ?. key ===
150+ streamedSourceKey ( threadRef , previewMiniPlayerSourceKey ( browserMiniPlayerSource ( tabId ) ) )
151+ ? state . viewport
148152 : null ,
149153 ) ;
150154 const sourceSize : PreviewMiniPlayerSize =
@@ -314,12 +318,15 @@ function BrowserMiniPlayer({ threadRef, tabId, miniPlayer }: Props & { readonly
314318 followSize = { false }
315319 controlPosition = "bottom"
316320 onViewport = { ( viewport ) =>
317- useStreamedSourceSizes . setState ( ( state ) => {
318- const current = state . viewports [ viewportKey ] ;
319- return current ?. width === viewport . width && current . height === viewport . height
320- ? state
321- : { viewports : { ...state . viewports , [ viewportKey ] : viewport } } ;
322- } )
321+ useStreamedSourceSize . setState (
322+ ( state ) =>
323+ state ?. key === viewportKey &&
324+ state . viewport . width === viewport . width &&
325+ state . viewport . height === viewport . height
326+ ? state
327+ : { key : viewportKey , viewport } ,
328+ true ,
329+ )
323330 }
324331 onPopup = { ( popupTabId ) => showPreviewPopup ( threadRef , popupTabId , "floating" ) }
325332 className = "size-full"
0 commit comments