@devries-cameron20 / t3code Mirror · read-only / commits / 6e6d1b4941
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 24, 16:30 UTC

fix(web): keep floating preview anchored after panel closes (#6547)

Akshar Patel committed Aug 15, 2026 at 08:00 UTC 6e6d1b49412d064ccbde7daae2e287f9b62efd7d
1 file changed +24 -7
apps/web/src/components/preview/ThreadPreviewMiniPlayer.tsx
+24 -7
@@ -2,7 +2,7 @@
2
3 import type { ScopedThreadRef } from "@t3tools/contracts";
4 import { PanelRightIcon, PictureInPicture2, XIcon } from "lucide-react";
5 -import { type PointerEvent as ReactPointerEvent, useLayoutEffect, useRef } from "react";
5 +import { type PointerEvent as ReactPointerEvent, useLayoutEffect, useRef, useState } from "react";
6
7 import { BrowserSurfaceSlot } from "~/browser/BrowserSurfaceSlot";
8 import { previewRuntimeTabId } from "~/browser/previewRuntimeTabId";
@@ -17,6 +17,7 @@ import {
17 clampPreviewMiniPlayerPosition,
18 clampPreviewMiniPlayerSize,
19 PREVIEW_MINI_PLAYER_DEFAULT_SIZE,
20 + PREVIEW_MINI_PLAYER_EDGE_GAP,
21 } from "./previewMiniPlayerLayout";
22
23 interface DragState {
@@ -31,6 +32,8 @@ interface ResizeState {
32 readonly pointerId: number;
33 readonly pointerX: number;
34 readonly pointerY: number;
35 + readonly playerX: number;
36 + readonly playerY: number;
37 readonly width: number;
38 readonly height: number;
39 }
@@ -45,6 +48,7 @@ export function ThreadPreviewMiniPlayer({ threadRef, tabId, bottomInset }: Props
48 const rootRef = useRef<HTMLElement | null>(null);
49 const dragRef = useRef<DragState | null>(null);
50 const resizeRef = useRef<ResizeState | null>(null);
51 + const [defaultLayoutVersion, setDefaultLayoutVersion] = useState("");
52 const miniPlayer = usePreviewMiniPlayerStore((state) =>
53 selectThreadPreviewMiniPlayer(state.byThreadKey, threadRef),
54 );
@@ -91,8 +95,12 @@ export function ThreadPreviewMiniPlayer({ threadRef, tabId, bottomInset }: Props
95 bottomInset,
96 );
97 usePreviewMiniPlayerStore.getState().resize(threadRef, tabId, nextSize);
98 + if (!position) {
99 + setDefaultLayoutVersion(`${parent.clientWidth}:${parent.clientHeight}`);
100 + return;
101 + }
102 const next = clampPreviewMiniPlayerPosition(
95 - position ?? { x: root.offsetLeft, y: root.offsetTop },
103 + position,
104 { width: parent.clientWidth, height: parent.clientHeight },
105 nextSize,
106 bottomInset,
@@ -159,11 +167,16 @@ export function ThreadPreviewMiniPlayer({ threadRef, tabId, bottomInset }: Props
167 const handleResizePointerDown = (event: ReactPointerEvent<HTMLButtonElement>) => {
168 if (event.button !== 0) return;
169 const root = rootRef.current;
162 - if (!root) return;
170 + const parent = root?.offsetParent;
171 + if (!root || !(parent instanceof HTMLElement)) return;
172 + const rootRect = root.getBoundingClientRect();
173 + const parentRect = parent.getBoundingClientRect();
174 resizeRef.current = {
175 pointerId: event.pointerId,
176 pointerX: event.clientX,
177 pointerY: event.clientY,
178 + playerX: rootRect.left - parentRect.left,
179 + playerY: rootRect.top - parentRect.top,
180 width: root.offsetWidth,
181 height: root.offsetHeight,
182 };
@@ -194,7 +207,7 @@ export function ThreadPreviewMiniPlayer({ threadRef, tabId, bottomInset }: Props
207 );
208 usePreviewMiniPlayerStore.getState().resize(threadRef, tabId, nextSize);
209 const nextPosition = clampPreviewMiniPlayerPosition(
197 - position ?? { x: root.offsetLeft, y: root.offsetTop },
210 + { x: resize.playerX, y: resize.playerY },
211 { width: parent.clientWidth, height: parent.clientHeight },
212 nextSize,
213 bottomInset,
@@ -222,8 +235,8 @@ export function ThreadPreviewMiniPlayer({ threadRef, tabId, bottomInset }: Props
235 position
236 ? { left: position.x, top: position.y, width: size.width, height: size.height }
237 : {
225 - right: 16,
226 - top: 16,
238 + right: PREVIEW_MINI_PLAYER_EDGE_GAP,
239 + top: PREVIEW_MINI_PLAYER_EDGE_GAP,
240 width: size.width,
241 height: size.height,
242 }
@@ -290,7 +303,11 @@ export function ThreadPreviewMiniPlayer({ threadRef, tabId, bottomInset }: Props
303 visible={Boolean(desktopOverlay?.hasWebContents)}
304 cornerRadius={12}
305 fitSourceContent
293 - layoutVersion={position ? `${position.x}:${position.y}` : `initial:${bottomInset}`}
306 + layoutVersion={
307 + position
308 + ? `${position.x}:${position.y}`
309 + : `initial:${bottomInset}:${defaultLayoutVersion}`
310 + }
311 className="absolute inset-0"
312 />
313 <div className="pointer-events-none absolute inset-0 z-[31] rounded-xl ring-1 ring-inset ring-border/80" />