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 21, 11:00 UTC
fix(web): attach command palette threads outside the sidebar (#37054)
Yash Singh committed
Nov 14, 2026 at 23:43 UTC
ab319a52dd532ef1720215510106acd132c3d3db
6 files changed
+54
-8
apps/web/src/components/CommandPalette.browser.test.tsx
+3
-1
@@ -81,7 +81,9 @@ describe("CommandPalette open intents", () => {
81
document.dispatchEvent(pointer("pointerup", 50, window.innerHeight - 30));
82
});
83
expect(onDrop).toHaveBeenCalledOnce();
84
- expect((onDrop.mock.calls[0]![0] as CustomEvent).detail).toEqual([{ environmentId, threadId }]);
84
+ expect((onDrop.mock.calls[0]![0] as CustomEvent).detail).toEqual([
85
+ { environmentId, threadId, title: "Drag this thread" },
86
+ ]);
87
expect(screen.router?.state.location.pathname).toBe(pathname);
88
});
89
apps/web/src/components/CommandPalette.drag.ts
+1
-1
@@ -22,7 +22,7 @@ export function startPaletteThreadDrag(
22
distance: 6,
23
onAttach: () => {},
24
onFinish: endThreadContextDrag,
25
- onDrop: (point) => dropThreadContext(point, [thread]),
25
+ onDrop: (point) => dropThreadContext(point, [{ ...thread, title }]),
26
},
27
onStart: () => {
28
flushSync(() => dispatchCommandPalette({ _tag: "SetOpen", open: false }));
apps/web/src/components/chat/ChatComposer.tsx
+3
-2
@@ -189,6 +189,7 @@ import {
189
} from "~/lib/composerContextRecords";
190
import { rememberCopiedComposerAttachments } from "~/lib/copiedComposerAttachments";
191
import { useThreadContextDrop, threadContextDropTargetProps } from "./threadContextDrag";
192
+import { droppedThreadContextRecord } from "./threadContextDrop.logic";
193
import { readThreadShell } from "~/state/entities";
194
import { useLinkedEnvironments } from "~/state/peerLinks";
195
import { encodeComposerContextFragment } from "@t3tools/shared/composerContextClipboard";
@@ -2877,8 +2878,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2878
);
2879
return [];
2880
}
2880
- const shell = readThreadShell(ref);
2881
- return shell ? [threadContextRecord(ref, shell.title)] : [];
2881
+ const record = droppedThreadContextRecord(ref, readThreadShell(ref));
2882
+ return record ? [record] : [];
2883
});
2884
if (records.length === 0) return;
2885
if (questionAttachmentTarget !== null) {
apps/web/src/components/chat/threadContextDrag.ts
+6
-4
@@ -1,13 +1,15 @@
1
-import type { EnvironmentId, ScopedThreadRef } from "@t3tools/contracts";
1
+import type { EnvironmentId } from "@t3tools/contracts";
2
import { type RefObject, useEffect, useEffectEvent, useSyncExternalStore } from "react";
3
4
+import type { ThreadContextDropRef } from "./threadContextDrop.logic";
5
+
6
export const THREAD_CONTEXT_DROP_EVENT = "t3-thread-context-drop";
7
8
export function useThreadContextDrop(
9
targetRef: RefObject<EventTarget | null>,
10
environmentId: EnvironmentId,
11
targetKey: string,
10
- onDrop: (refs: ReadonlyArray<ScopedThreadRef>, isActive: () => boolean) => void,
12
+ onDrop: (refs: ReadonlyArray<ThreadContextDropRef>, isActive: () => boolean) => void,
13
) {
14
const handleDrop = useEffectEvent(onDrop);
15
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes the target element to thread-context drop events and marks old drops inactive
@@ -16,7 +18,7 @@ export function useThreadContextDrop(
18
if (!target) return;
19
let active = true;
20
const listener = (event: Event) =>
19
- handleDrop((event as CustomEvent<ReadonlyArray<ScopedThreadRef>>).detail, () => active);
21
+ handleDrop((event as CustomEvent<ReadonlyArray<ThreadContextDropRef>>).detail, () => active);
22
target.addEventListener(THREAD_CONTEXT_DROP_EVENT, listener);
23
return () => {
24
active = false;
@@ -91,7 +93,7 @@ export function endThreadContextDrag() {
93
94
export function dropThreadContext(
95
point: { x: number; y: number },
94
- threads: ReadonlyArray<ScopedThreadRef>,
96
+ threads: ReadonlyArray<ThreadContextDropRef>,
97
): boolean {
98
const target = findDropTarget(point);
99
if (!target || threads.length === 0) return false;
apps/web/src/components/chat/threadContextDrop.logic.test.ts
new
+29
@@ -0,0 +1,29 @@
1
+import { EnvironmentId, ThreadId } from "@t3tools/contracts";
2
+import { threadContextRecord } from "@t3tools/shared/composerContextReferences";
3
+import { describe, expect, it } from "vite-plus/test";
4
+import { droppedThreadContextRecord } from "./threadContextDrop.logic";
5
+
6
+describe("droppedThreadContextRecord", () => {
7
+ it.each([null, { title: "Cached title" }])(
8
+ "uses the search result title even when the sidebar shell is %s",
9
+ (shell) => {
10
+ const ref = {
11
+ environmentId: EnvironmentId.make("remote"),
12
+ threadId: ThreadId.make("search-result"),
13
+ title: "Search result",
14
+ };
15
+ expect(droppedThreadContextRecord(ref, shell)).toEqual(threadContextRecord(ref, ref.title));
16
+ },
17
+ );
18
+
19
+ it("uses the sidebar title for a drag without search metadata", () => {
20
+ const ref = {
21
+ environmentId: EnvironmentId.make("local"),
22
+ threadId: ThreadId.make("sidebar-thread"),
23
+ };
24
+ expect(droppedThreadContextRecord(ref, { title: "Sidebar thread" })).toEqual(
25
+ threadContextRecord(ref, "Sidebar thread"),
26
+ );
27
+ expect(droppedThreadContextRecord(ref, null)).toBeNull();
28
+ });
29
+});
apps/web/src/components/chat/threadContextDrop.logic.ts
new
+12
@@ -0,0 +1,12 @@
1
+import type { ScopedThreadRef } from "@t3tools/contracts";
2
+import { threadContextRecord } from "@t3tools/shared/composerContextReferences";
3
+
4
+export type ThreadContextDropRef = ScopedThreadRef & { readonly title?: string };
5
+
6
+export function droppedThreadContextRecord(
7
+ ref: ThreadContextDropRef,
8
+ shell: { readonly title: string } | null,
9
+) {
10
+ const title = ref.title ?? shell?.title;
11
+ return title === undefined ? null : threadContextRecord(ref, title);
12
+}