Skip to content

Commit 05f911d

Browse files
fix(web): mini player keeps one streamed viewport size, not one per tab
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 0447af8 commit 05f911d

2 files changed

Lines changed: 25 additions & 17 deletions

File tree

‎apps/web/src/components/chat/ThreadDetailsCard.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ export function ThreadDetailsCard({
7575
? current
7676
: { key: measurementKey, heights: { ...heights, [density]: fittingHeight } };
7777
});
78-
// The canvas keeps preview frames clear of the full card.
78+
// Only the laid-out DOM knows the full card height, and the canvas keeps preview
79+
// frames clear of it, so it is reported from this measure effect.
7980
if (density === "full" && cardWidth !== undefined) {
8081
measureDetailsCard?.({
8182
threadRef: { environmentId, threadId },

‎apps/web/src/components/preview/ThreadPreviewMiniPlayer.tsx‎

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

111114
const 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

Comments
 (0)