@@ -45,24 +45,15 @@ export function ShellTerminal({ cwd }: ShellTerminalProps) {
4545 } , [ cliMode ] ) ;
4646
4747 useEffect ( ( ) => {
48- console . log ( "[ShellTerminal] Effect running" , {
49- hasRef : ! ! terminalRef . current ,
50- hasTerminal : ! ! terminal . current ,
51- } ) ;
52-
5348 if ( ! terminalRef . current ) {
54- console . log ( "[ShellTerminal] No terminalRef, returning" ) ;
5549 return ;
5650 }
5751
5852 // Don't recreate if already exists
5953 if ( terminal . current ) {
60- console . log ( "[ShellTerminal] Terminal already exists, returning" ) ;
6154 return ;
6255 }
6356
64- console . log ( "[ShellTerminal] Creating terminal..." ) ;
65-
6657 // Generate unique session ID for this effect run using cryptographically secure random
6758 const sessionId = `shell-${ Date . now ( ) } -${ secureRandomString ( 7 ) } ` ;
6859 sessionIdRef . current = sessionId ;
@@ -115,13 +106,15 @@ export function ShellTerminal({ cwd }: ShellTerminalProps) {
115106 // Open terminal
116107 term . open ( terminalRef . current ) ;
117108
118- // Fit terminal to container
119- fit . fit ( ) ;
120-
121109 // Store refs
122110 terminal . current = term ;
123111 fitAddon . current = fit ;
124112
113+ // Fit terminal to container after it's fully initialized
114+ setTimeout ( ( ) => {
115+ fit . fit ( ) ;
116+ } , 0 ) ;
117+
125118 // Create PTY session
126119 window . electronAPI ?. shellCreate ( sessionId , cwd ) . catch ( ( error : Error ) => {
127120 console . error ( "Failed to create shell session:" , error ) ;
@@ -152,25 +145,21 @@ export function ShellTerminal({ cwd }: ShellTerminalProps) {
152145
153146 // Handle resize
154147 const handleResize = ( ) => {
155- if ( fit && term ) {
156- fit . fit ( ) ;
148+ if ( fitAddon . current && terminal . current ) {
149+ fitAddon . current . fit ( ) ;
157150 window . electronAPI
158- ?. shellResize ( sessionId , term . cols , term . rows )
151+ ?. shellResize ( sessionId , terminal . current . cols , terminal . current . rows )
159152 . catch ( ( error : Error ) => {
160153 console . error ( "Failed to resize shell:" , error ) ;
161154 } ) ;
162155 }
163156 } ;
164157
165- // Initial resize
166- handleResize ( ) ;
167-
168158 // Listen for window resize
169159 window . addEventListener ( "resize" , handleResize ) ;
170160
171161 // Cleanup
172162 return ( ) => {
173- console . log ( "[ShellTerminal] Cleanup running, disposing terminal" ) ;
174163 window . removeEventListener ( "resize" , handleResize ) ;
175164 disposable . dispose ( ) ;
176165 unsubscribeData ?.( ) ;
@@ -181,9 +170,6 @@ export function ShellTerminal({ cwd }: ShellTerminalProps) {
181170 term . dispose ( ) ;
182171 terminal . current = null ;
183172 fitAddon . current = null ;
184- console . log (
185- "[ShellTerminal] Cleanup complete, terminal.current set to null" ,
186- ) ;
187173 } ;
188174 } , [ cwd , setCliMode ] ) ;
189175
0 commit comments