@@ -31,7 +31,7 @@ import {
3131import { applyClaudePromptEffortPrefix , normalizeModelSlug } from "@t3tools/shared/model" ;
3232import { projectScriptCwd , projectScriptRuntimeEnv } from "@t3tools/shared/projectScripts" ;
3333import { truncate } from "@t3tools/shared/String" ;
34- import { useCallback , useEffect , useLayoutEffect , useMemo , useRef , useState } from "react" ;
34+ import { memo , useCallback , useEffect , useLayoutEffect , useMemo , useRef , useState } from "react" ;
3535import { useQuery } from "@tanstack/react-query" ;
3636import { useDebouncedValue } from "@tanstack/react-pacer" ;
3737import { useNavigate , useSearch } from "@tanstack/react-router" ;
@@ -491,7 +491,7 @@ interface PersistentThreadTerminalDrawerProps {
491491 onAddTerminalContext : ( selection : TerminalContextSelection ) => void ;
492492}
493493
494- function PersistentThreadTerminalDrawer ( {
494+ const PersistentThreadTerminalDrawer = memo ( function PersistentThreadTerminalDrawer ( {
495495 threadRef,
496496 threadId,
497497 visible,
@@ -650,7 +650,7 @@ function PersistentThreadTerminalDrawer({
650650 />
651651 </ div >
652652 ) ;
653- }
653+ } ) ;
654654
655655export default function ChatView ( props : ChatViewProps ) {
656656 const { environmentId, threadId, routeKind } = props ;
@@ -867,6 +867,14 @@ export default function ChatView(props: ChatViewProps) {
867867 [ draftThreadsByThreadKey ] ,
868868 ) ;
869869 const [ mountedTerminalThreadKeys , setMountedTerminalThreadKeys ] = useState < string [ ] > ( [ ] ) ;
870+ const mountedTerminalThreadRefs = useMemo (
871+ ( ) =>
872+ mountedTerminalThreadKeys . flatMap ( ( mountedThreadKey ) => {
873+ const mountedThreadRef = parseScopedThreadKey ( mountedThreadKey ) ;
874+ return mountedThreadRef ? [ { key : mountedThreadKey , threadRef : mountedThreadRef } ] : [ ] ;
875+ } ) ,
876+ [ mountedTerminalThreadKeys ] ,
877+ ) ;
870878
871879 const setPrompt = useCallback (
872880 ( nextPrompt : string ) => {
@@ -4850,28 +4858,22 @@ export default function ChatView(props: ChatViewProps) {
48504858 </ div >
48514859 { /* end horizontal flex container */ }
48524860
4853- { mountedTerminalThreadKeys . flatMap ( ( mountedThreadKey ) => {
4854- const mountedThreadRef = parseScopedThreadKey ( mountedThreadKey ) ;
4855- if ( ! mountedThreadRef ) {
4856- return [ ] ;
4857- }
4858- return [
4859- < PersistentThreadTerminalDrawer
4860- key = { mountedThreadKey }
4861- threadRef = { mountedThreadRef }
4862- threadId = { mountedThreadRef . threadId }
4863- visible = { mountedThreadKey === activeThreadKey && terminalState . terminalOpen }
4864- launchContext = {
4865- mountedThreadKey === activeThreadKey ? ( activeTerminalLaunchContext ?? null ) : null
4866- }
4867- focusRequestId = { mountedThreadKey === activeThreadKey ? terminalFocusRequestId : 0 }
4868- splitShortcutLabel = { splitTerminalShortcutLabel ?? undefined }
4869- newShortcutLabel = { newTerminalShortcutLabel ?? undefined }
4870- closeShortcutLabel = { closeTerminalShortcutLabel ?? undefined }
4871- onAddTerminalContext = { addTerminalContextToDraft }
4872- /> ,
4873- ] ;
4874- } ) }
4861+ { mountedTerminalThreadRefs . map ( ( { key : mountedThreadKey , threadRef : mountedThreadRef } ) => (
4862+ < PersistentThreadTerminalDrawer
4863+ key = { mountedThreadKey }
4864+ threadRef = { mountedThreadRef }
4865+ threadId = { mountedThreadRef . threadId }
4866+ visible = { mountedThreadKey === activeThreadKey && terminalState . terminalOpen }
4867+ launchContext = {
4868+ mountedThreadKey === activeThreadKey ? ( activeTerminalLaunchContext ?? null ) : null
4869+ }
4870+ focusRequestId = { mountedThreadKey === activeThreadKey ? terminalFocusRequestId : 0 }
4871+ splitShortcutLabel = { splitTerminalShortcutLabel ?? undefined }
4872+ newShortcutLabel = { newTerminalShortcutLabel ?? undefined }
4873+ closeShortcutLabel = { closeTerminalShortcutLabel ?? undefined }
4874+ onAddTerminalContext = { addTerminalContextToDraft }
4875+ />
4876+ ) ) }
48754877
48764878 { expandedImage && expandedImageItem && (
48774879 < div
0 commit comments