|
| 1 | +import { scopedThreadKey } from "@t3tools/client-runtime/environment"; |
1 | 2 | import { useNavigate } from "@tanstack/react-router"; |
2 | 3 | import { Columns2, Maximize2, Minimize2, Rows2, X } from "lucide-react"; |
3 | 4 | import { memo, type CSSProperties, useRef, useState, useEffect, useLayoutEffect } from "react"; |
@@ -28,6 +29,12 @@ interface SplitChatWorkspaceProps { |
28 | 29 | readonly modalOpen: boolean; |
29 | 30 | } |
30 | 31 |
|
| 32 | +// Stays the draft's key after promotion so the pane keeps its ChatView mounted. |
| 33 | +function paneKey(target: ThreadRouteTarget | undefined): string { |
| 34 | + if (!target) return ""; |
| 35 | + return target.kind === "server" ? scopedThreadKey(target.threadRef) : `draft:${target.draftId}`; |
| 36 | +} |
| 37 | + |
31 | 38 | export const SplitChatWorkspace = memo(function SplitChatWorkspace({ |
32 | 39 | primaryTarget, |
33 | 40 | modalOpen, |
@@ -144,7 +151,7 @@ export const SplitChatWorkspace = memo(function SplitChatWorkspace({ |
144 | 151 | ? Math.min(index, next.length - 1) |
145 | 152 | : activeIndex; |
146 | 153 | if (index === 0) navigatePrimary(nextPrimary); |
147 | | - if (activeIndex === index) focusTargetRef.current = threadTargetKey(next[active]); |
| 154 | + if (activeIndex === index) focusTargetRef.current = paneKey(next[active]); |
148 | 155 | store.replaceSecondaryPanes(next.slice(1), active); |
149 | 156 | }; |
150 | 157 | const resolveDrop = ( |
@@ -190,7 +197,7 @@ export const SplitChatWorkspace = memo(function SplitChatWorkspace({ |
190 | 197 | if (!nextPrimary) return false; |
191 | 198 | if (threadTargetKey(nextPrimary) !== threadTargetKey(effectivePrimary)) |
192 | 199 | navigatePrimary(nextPrimary); |
193 | | - focusTargetRef.current = threadTargetKey(target); |
| 200 | + focusTargetRef.current = paneKey(target); |
194 | 201 | store.replaceSecondaryPanes(next.slice(1), zone.index); |
195 | 202 | setDropZone(null); |
196 | 203 | return true; |
@@ -298,9 +305,9 @@ export const SplitChatWorkspace = memo(function SplitChatWorkspace({ |
298 | 305 | {panes.map((target, index) => ( |
299 | 306 | <div |
300 | 307 | // The primary pane keeps one key so draft promotion keeps its ChatView mounted. |
301 | | - key={index === 0 ? "primary" : threadTargetKey(target)} |
| 308 | + key={index === 0 ? "primary" : paneKey(target)} |
302 | 309 | data-split-pane-index={index} |
303 | | - data-split-pane-key={threadTargetKey(target)} |
| 310 | + data-split-pane-key={paneKey(target)} |
304 | 311 | tabIndex={-1} |
305 | 312 | hidden={maximized !== null && maximized !== index} |
306 | 313 | style={{ |
|
0 commit comments