Skip to content

Commit 9c5f157

Browse files
refactor(web): ChatView's right panel lives in its own component
The inline and sheet layouts shared one long prop list, written out twice. The panel's width also follows a resize drag every frame; keeping that state in the panel stops the drag from re-rendering ChatView. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ff41fc5 commit 9c5f157

3 files changed

Lines changed: 66 additions & 69 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 14 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ import { settleAndAdvance } from "../settleAndAdvance";
212212
import { subscribeSnapShotComposerFocus } from "../lib/desktopSnapShot";
213213
import { useMediaQuery } from "../hooks/useMediaQuery";
214214
import { FileMetadataThreadProvider } from "../hooks/FileMetadataThreadProvider";
215-
import { usePreviewPanelInlineSize } from "../hooks/usePreviewPanelInlineSize";
216215
import {
217216
RIGHT_PANEL_INLINE_LAYOUT_MEDIA_QUERY,
218217
type ThreadPanelPresentation,
@@ -247,7 +246,6 @@ import {
247246
usePreviewMiniPlayerStore,
248247
} from "../previewMiniPlayerStore";
249248
import { threadPullRequestPanelTarget } from "./pullRequest/pullRequestDetail.logic";
250-
import { RightPanelTabs } from "./RightPanelTabs";
251249
import { LinkPullRequestDialogHost } from "./pullRequest/LinkPullRequestDialog";
252250
import { useDeviceState } from "~/state/device";
253251
import { BranchToolbar, type BranchToolbarHandle } from "./BranchToolbar";
@@ -509,7 +507,6 @@ import {
509507
retryAttachmentUpload,
510508
startAttachmentUpload,
511509
} from "../lib/attachmentUploadQueue";
512-
import { RightPanelSheet } from "./RightPanelSheet";
513510
import { previewEnvironment } from "../state/preview";
514511
import { clampFileAttachmentUploadBytes } from "@t3tools/client-runtime/state/attachments";
515512
import { appAtomRegistry } from "../rpc/atomRegistry";
@@ -544,6 +541,7 @@ import {
544541
import { observeResize } from "~/lib/observeResize";
545542
import { ThreadVisitWatermark } from "./chat/ThreadVisitWatermark";
546543
import { ChatTerminalDrawers } from "./chat/ChatTerminalDrawers";
544+
import { ChatRightPanel } from "./chat/ChatRightPanel";
547545
import { useDraftHeroLayoutTransition } from "./chat/useDraftHeroLayoutTransition";
548546
import { useLocalDispatchState } from "./chat/useLocalDispatchState";
549547
import {
@@ -1209,10 +1207,6 @@ export default function ChatView(props: ChatViewProps) {
12091207
activeThreadRef?.environmentId ?? null,
12101208
);
12111209
const browserAvailable = isPreviewSupportedInRuntime() || activeEnvironmentServerBrowser;
1212-
const previewPanelInlineSize = usePreviewPanelInlineSize(undefined, {
1213-
container: workspaceLayoutElement,
1214-
widthStorageKey: `t3code:preview-panel-width:${activeThreadKey}`,
1215-
});
12161210
const activeThreadShell = serverThread;
12171211
const timelineThreadError =
12181212
serverRuntime?.status === "failed" &&
@@ -8405,14 +8399,22 @@ export default function ChatView(props: ChatViewProps) {
84058399
/>
84068400
</div>
84078401

8408-
{rightPanelPresent && !shouldUsePlanSidebarSheet && activeThreadRef ? (
8409-
<RightPanelTabs
8410-
mode="inline"
8402+
{rightPanelPresent && activeThreadRef ? (
8403+
<ChatRightPanel
8404+
sheet={shouldUsePlanSidebarSheet}
8405+
workspaceLayoutElement={workspaceLayoutElement}
8406+
widthStorageKey={`t3code:preview-panel-width:${activeThreadKey}`}
8407+
sheetAnimationDurationMs={panelAnimationsActive ? panelAnimationDurationMs : 0}
8408+
onCloseSheet={closePreviewPanelStable}
84118409
open={rightPanelOpen}
84128410
keybindings={keybindings}
84138411
getShortcutContext={getShortcutContextStable}
84148412
maximized={rightPanelMaximized}
8415-
inlineSize={previewPanelInlineSize}
8413+
layoutControls={
8414+
rightPanelOpen ? (
8415+
<div className="mr-px flex items-center">{panelToggleControls}</div>
8416+
) : null
8417+
}
84168418
surfaces={renderedRightPanelSurfaces}
84178419
environmentId={activeThreadRef.environmentId}
84188420
activeSurfaceId={renderedRightPanelSurface?.id ?? null}
@@ -8449,63 +8451,7 @@ export default function ChatView(props: ChatViewProps) {
84498451
deviceAvailable={activeThreadRef !== null}
84508452
>
84518453
{rightPanelContent}
8452-
</RightPanelTabs>
8453-
) : null}
8454-
{rightPanelPresent && shouldUsePlanSidebarSheet && activeThreadRef ? (
8455-
<RightPanelSheet
8456-
animationDurationMs={panelAnimationsActive ? panelAnimationDurationMs : 0}
8457-
open={rightPanelOpen}
8458-
onClose={closePreviewPanelStable}
8459-
>
8460-
<RightPanelTabs
8461-
mode="sheet"
8462-
open={rightPanelOpen}
8463-
keybindings={keybindings}
8464-
getShortcutContext={getShortcutContextStable}
8465-
inlineSize={previewPanelInlineSize}
8466-
layoutControls={
8467-
rightPanelOpen ? (
8468-
<div className="mr-px flex items-center">{panelToggleControls}</div>
8469-
) : null
8470-
}
8471-
surfaces={renderedRightPanelSurfaces}
8472-
environmentId={activeThreadRef.environmentId}
8473-
activeSurfaceId={renderedRightPanelSurface?.id ?? null}
8474-
pendingSurfaceIds={pendingFileSurfaceIds}
8475-
previewSessions={activePreviewState.sessions}
8476-
desktopByTabId={activePreviewState.desktopByTabId}
8477-
previewRuntimeTabId={resolvePreviewRuntimeTabId}
8478-
terminalLabelsById={activeTerminalLabelsById}
8479-
onActivate={activateRightPanelSurfaceStable}
8480-
onCloseSurface={closeRightPanelSurfaceStable}
8481-
onRenameDevice={(surfaceId, title) => {
8482-
if (activeThreadRef)
8483-
useRightPanelStore.getState().renameDevice(activeThreadRef, surfaceId, title);
8484-
}}
8485-
onCloseOtherSurfaces={closeOtherRightPanelSurfacesStable}
8486-
onCloseSurfacesToRight={closeRightPanelSurfacesToRightStable}
8487-
onCloseAllSurfaces={closeAllRightPanelSurfacesStable}
8488-
onMoveSurface={moveRightPanelSurfaceStable}
8489-
onCopyFilePath={copyRightPanelFilePathStable}
8490-
onAddBrowser={() => createBrowserSurface()}
8491-
onAddBrowserInProfile={createBrowserSurfaceStable}
8492-
onAddTerminal={addTerminalSurfaceStable}
8493-
onAddDiff={addDiffSurfaceStable}
8494-
onAddFiles={addFilesSurfaceStable}
8495-
onAddPullRequest={addPullRequestSurfaceStable}
8496-
onAddPullRequests={addPullRequestsSurfaceStable}
8497-
onAddDevice={addDeviceSurfaceStable}
8498-
browserAvailable={canOperatePreview && browserAvailable}
8499-
terminalAvailable={activeProject !== null && canOperateTerminal}
8500-
diffAvailable={isServerThread && isGitRepo}
8501-
filesAvailable={activeProject !== null}
8502-
pullRequestAvailable={pullRequestSurfaceAvailable}
8503-
pullRequestsAvailable={pullRequestsSurfaceAvailable}
8504-
deviceAvailable={activeThreadRef !== null}
8505-
>
8506-
{rightPanelContent}
8507-
</RightPanelTabs>
8508-
</RightPanelSheet>
8454+
</ChatRightPanel>
85098455
) : null}
85108456

85118457
<RevertConfirmHost threadKey={routeThreadKey} onConfirm={onConfirmRevertStable} />

‎apps/web/src/components/RightPanelTabs.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ import { resolvePullRequestState } from "./pullRequest/pullRequestPresentation";
9393
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
9494
import { observeResize } from "~/lib/observeResize";
9595

96-
interface RightPanelTabsProps {
96+
export interface RightPanelTabsProps {
9797
mode: PreviewPanelMode;
9898
maximized?: boolean;
9999
open?: boolean;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { usePreviewPanelInlineSize } from "../../hooks/usePreviewPanelInlineSize";
2+
import { RightPanelSheet } from "../RightPanelSheet";
3+
import { RightPanelTabs, type RightPanelTabsProps } from "../RightPanelTabs";
4+
5+
type ChatRightPanelProps = Omit<RightPanelTabsProps, "mode" | "inlineSize" | "maximized"> & {
6+
readonly sheet: boolean;
7+
readonly maximized: boolean;
8+
readonly workspaceLayoutElement: HTMLElement | null;
9+
readonly widthStorageKey: string;
10+
readonly sheetAnimationDurationMs: number;
11+
readonly onCloseSheet: () => void;
12+
};
13+
14+
/**
15+
* The right panel, inline beside the chat column or as a sheet on narrow
16+
* layouts. Its width follows a resize drag every frame, so the width state
17+
* lives here rather than in ChatView.
18+
*/
19+
export function ChatRightPanel(props: ChatRightPanelProps) {
20+
const {
21+
sheet,
22+
workspaceLayoutElement,
23+
widthStorageKey,
24+
sheetAnimationDurationMs,
25+
onCloseSheet,
26+
maximized,
27+
layoutControls,
28+
...tabs
29+
} = props;
30+
const inlineSize = usePreviewPanelInlineSize(undefined, {
31+
container: workspaceLayoutElement,
32+
widthStorageKey,
33+
});
34+
if (!sheet) {
35+
return <RightPanelTabs {...tabs} mode="inline" maximized={maximized} inlineSize={inlineSize} />;
36+
}
37+
return (
38+
<RightPanelSheet
39+
animationDurationMs={sheetAnimationDurationMs}
40+
open={tabs.open === true}
41+
onClose={onCloseSheet}
42+
>
43+
<RightPanelTabs
44+
{...tabs}
45+
mode="sheet"
46+
inlineSize={inlineSize}
47+
layoutControls={layoutControls}
48+
/>
49+
</RightPanelSheet>
50+
);
51+
}

0 commit comments

Comments
 (0)