@@ -5,14 +5,14 @@ import type { ScopedThreadRef } from "@t3tools/contracts";
55
66import { ComposerHandleContext , useComposerHandleContext } from "../../composerHandleContext" ;
77import type { ChatComposerHandle } from "../chat/ChatComposer" ;
8- import { DiffWorkerPoolProvider } from "../DiffWorkerPoolProvider" ;
98import { useMediaQuery } from "../../hooks/useMediaQuery" ;
109import { resolveThreadRouteRef } from "../../threadRoutes" ;
1110import { ServerThreadPaneHost } from "./ServerThreadPaneHost" ;
1211import { ThreadPaneContext } from "./threadPaneContext" ;
1312import {
1413 clampSplitRatio ,
1514 noteThreadPaneFocus ,
15+ reclaimThreadPaneFocus ,
1616 registerThreadPaneComposer ,
1717 registerThreadPaneRoot ,
1818 THREAD_SPLIT_MEDIA_QUERY ,
@@ -31,9 +31,10 @@ const SINGLE_GRID_TEMPLATE_COLUMNS = "minmax(0, 1fr)";
3131 * Wraps the chat routes' content. The tree shape is identical whether the
3232 * split is open or closed — only the separator and the secondary pane mount
3333 * and unmount — so toggling the split never remounts the routed ChatView
34- * (which would reload previews, terminals, and scroll positions). The shared
35- * DiffWorkerPoolProvider up here also means both panes reuse one worker pool
36- * instead of spawning one per ChatView.
34+ * instance. (Its right panel still remounts on toggle: the split forces the
35+ * sheet presentation, which lives in a different tree position than the
36+ * inline one.) No diff worker pool is hoisted here on purpose: the pool is a
37+ * module singleton, so both panes' ChatView-level providers already share it.
3738 */
3839export function SplitThreadLayout ( { children } : { children : ReactNode } ) {
3940 const secondaryRef = useThreadSplitStore ( ( state ) => state . secondaryRef ) ;
@@ -67,9 +68,7 @@ export function SplitThreadLayout({ children }: { children: ReactNode }) {
6768 const splitOpen = secondaryRef !== null && isWideEnoughForSplit ;
6869
6970 return (
70- < DiffWorkerPoolProvider >
71- < SplitThreadPanes secondaryRef = { splitOpen ? secondaryRef : null } > { children } </ SplitThreadPanes >
72- </ DiffWorkerPoolProvider >
71+ < SplitThreadPanes secondaryRef = { splitOpen ? secondaryRef : null } > { children } </ SplitThreadPanes >
7372 ) ;
7473}
7574
@@ -163,7 +162,10 @@ function ThreadPaneSection({
163162 data-thread-pane-id = { paneId }
164163 data-active = { isActive ? "true" : "false" }
165164 className = "relative h-full min-h-0 min-w-0 outline-none"
166- onPointerDownCapture = { ( ) => setActivePane ( paneId ) }
165+ onPointerDownCapture = { ( ) => {
166+ setActivePane ( paneId ) ;
167+ reclaimThreadPaneFocus ( paneId ) ;
168+ } }
167169 onFocusCapture = { ( event ) => {
168170 setActivePane ( paneId ) ;
169171 noteThreadPaneFocus ( paneId , event . target ) ;
@@ -186,7 +188,15 @@ function SplitResizeHandle({
186188 containerRef : React . RefObject < HTMLDivElement | null > ;
187189} ) {
188190 const setSplitRatio = useThreadSplitStore ( ( state ) => state . setSplitRatio ) ;
189- const dragStateRef = useRef < { pointerId : number ; ratio : number } | null > ( null ) ;
191+ const dragStateRef = useRef < {
192+ pointerId : number ;
193+ ratio : number ;
194+ // Captured once at pointerdown: reading getBoundingClientRect per
195+ // pointermove would force a synchronous layout of both panes on every
196+ // move, defeating the rAF write coalescing below.
197+ boundsLeft : number ;
198+ boundsWidth : number ;
199+ } | null > ( null ) ;
190200 const frameRef = useRef < number | null > ( null ) ;
191201
192202 const applyRatio = useCallback (
@@ -206,21 +216,26 @@ function SplitResizeHandle({
206216 className = "relative z-40 h-full w-1 shrink-0 cursor-col-resize bg-border/60 hover:bg-primary/40 data-[dragging=true]:bg-primary/60"
207217 onPointerDown = { ( event ) => {
208218 if ( event . button !== 0 ) return ;
219+ const container = containerRef . current ;
220+ if ( ! container ) return ;
221+ const bounds = container . getBoundingClientRect ( ) ;
222+ if ( bounds . width <= 0 ) return ;
209223 event . preventDefault ( ) ;
210224 event . currentTarget . setPointerCapture ( event . pointerId ) ;
211225 event . currentTarget . dataset . dragging = "true" ;
212226 dragStateRef . current = {
213227 pointerId : event . pointerId ,
214228 ratio : useThreadSplitStore . getState ( ) . splitRatio ,
229+ boundsLeft : bounds . left ,
230+ boundsWidth : bounds . width ,
215231 } ;
216232 } }
217233 onPointerMove = { ( event ) => {
218234 const dragState = dragStateRef . current ;
219- const container = containerRef . current ;
220- if ( ! dragState || dragState . pointerId !== event . pointerId || ! container ) return ;
221- const bounds = container . getBoundingClientRect ( ) ;
222- if ( bounds . width <= 0 ) return ;
223- dragState . ratio = clampSplitRatio ( ( event . clientX - bounds . left ) / bounds . width ) ;
235+ if ( ! dragState || dragState . pointerId !== event . pointerId ) return ;
236+ dragState . ratio = clampSplitRatio (
237+ ( event . clientX - dragState . boundsLeft ) / dragState . boundsWidth ,
238+ ) ;
224239 if ( frameRef . current === null ) {
225240 frameRef . current = window . requestAnimationFrame ( ( ) => {
226241 frameRef . current = null ;
@@ -240,8 +255,9 @@ function SplitResizeHandle({
240255 }
241256 setSplitRatio ( dragState . ratio ) ;
242257 } }
243- onPointerCancel = { ( ) => {
258+ onPointerCancel = { ( event ) => {
244259 dragStateRef . current = null ;
260+ delete event . currentTarget . dataset . dragging ;
245261 if ( frameRef . current !== null ) {
246262 window . cancelAnimationFrame ( frameRef . current ) ;
247263 frameRef . current = null ;
0 commit comments