Skip to content

Commit 7e88d5b

Browse files
t3dotggclaude
andcommitted
fix(web): links and files clicked in a side chat open in the parent's panel
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5a99500 commit 7e88d5b

3 files changed

Lines changed: 49 additions & 2 deletions

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import {
1111
type ThreadId,
1212
} from "@t3tools/contracts";
1313
import { XIcon } from "lucide-react";
14-
import { useState } from "react";
14+
import { useEffect, useState } from "react";
1515

1616
import { ComposerHandleContext } from "../../composerHandleContext";
1717
import type { SideChatParentPanel } from "../../lib/sideChatPane";
18+
import { hostRightPanel } from "../../rightPanelStore";
1819
import { useQuietThreadProjection, useQuietThreadShell } from "../../state/entities";
1920
import { useEnvironmentScope } from "../../state/session";
2021
import { useEnvironmentShellHasSnapshot } from "../../state/shell";
@@ -35,6 +36,11 @@ export default function SideChatPane(props: {
3536
}) {
3637
const { parentRef, threadId } = props;
3738
const threadRef = scopeThreadRef(parentRef.environmentId, threadId);
39+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- registers the parent panel as host in the panel store
40+
useEffect(
41+
() => hostRightPanel(scopeThreadRef(parentRef.environmentId, threadId), parentRef),
42+
[parentRef, threadId],
43+
);
3844
const shell = useQuietThreadShell(threadRef);
3945
const parent = useQuietThreadShell(parentRef);
4046
const snapshotLoaded = useEnvironmentShellHasSnapshot(parentRef.environmentId);

‎apps/web/src/rightPanelStore.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { beforeEach, describe, expect, it } from "vite-plus/test";
55
import { useClosedViewStore } from "./closedViewStore";
66
import { reopenClosedView } from "./reopenClosedView";
77
import {
8+
hostRightPanel,
89
migratePersistedRightPanelState,
910
pullRequestSurface,
1011
pullRequestSurfaceId,
@@ -39,6 +40,23 @@ async function reloadRightPanelStore() {
3940
}
4041

4142
describe("rightPanelStore", () => {
43+
it("opens a hosted side chat's panel actions in its parent's panel until unhosted", () => {
44+
const store = useRightPanelStore.getState();
45+
const unhost = hostRightPanel(refB, refA);
46+
store.openFile(refB, "src/app.ts");
47+
expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refA)?.id).toBe(
48+
"file:src/app.ts",
49+
);
50+
expect(
51+
selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refB).surfaces,
52+
).toEqual([]);
53+
unhost();
54+
store.openFile(refB, "src/app.ts");
55+
expect(selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, refB)?.id).toBe(
56+
"file:src/app.ts",
57+
);
58+
});
59+
4260
it("records single and bulk tab closes, newest first", () => {
4361
const store = useRightPanelStore.getState();
4462
const pr = pullRequestSurface({

‎apps/web/src/rightPanelStore.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,34 @@ const automaticUpdate = (
384384
...updateThread(state, threadKey, updater),
385385
});
386386

387+
// A side chat pane has no panel of its own, so its panel actions open in its parent's panel.
388+
const panelHosts = new Map<string, string>();
389+
390+
/** Routes `guest`'s panel actions to `host`'s panel until the returned cleanup runs. */
391+
export function hostRightPanel(guest: ScopedThreadRef, host: ScopedThreadRef): () => void {
392+
const guestKey = scopedThreadKey(guest);
393+
const hostKey = scopedThreadKey(host);
394+
panelHosts.set(guestKey, hostKey);
395+
return () => {
396+
if (panelHosts.get(guestKey) === hostKey) panelHosts.delete(guestKey);
397+
};
398+
}
399+
387400
const userAction = (
388401
state: RightPanelStoreState,
389-
threadKey: string,
402+
guestKey: string,
390403
updater: (current: ThreadRightPanelState) => ThreadRightPanelState,
391404
closesView = false,
405+
): Partial<RightPanelStoreState> => {
406+
const threadKey = panelHosts.get(guestKey) ?? guestKey;
407+
return userActionOnThread(state, threadKey, updater, closesView);
408+
};
409+
410+
const userActionOnThread = (
411+
state: RightPanelStoreState,
412+
threadKey: string,
413+
updater: (current: ThreadRightPanelState) => ThreadRightPanelState,
414+
closesView: boolean,
392415
): Partial<RightPanelStoreState> => ({
393416
...updateThread(state, threadKey, (current) => {
394417
const next = updater(current);

0 commit comments

Comments
 (0)