11'use client' ;
22
3- import { useState , useEffect , useRef } from 'react' ;
3+ import { useState , useEffect , useRef , useCallback , useMemo } from 'react' ;
44import { api } from '~/trpc/react' ;
55import { Terminal } from './Terminal' ;
66import { StatusBadge } from './Badge' ;
@@ -160,11 +160,11 @@ export function InstalledScriptsTab() {
160160 } ) ;
161161
162162
163- const scripts : InstalledScript [ ] = ( scriptsData ?. scripts as InstalledScript [ ] ) ?? [ ] ;
163+ const scripts : InstalledScript [ ] = useMemo ( ( ) => ( scriptsData ?. scripts as InstalledScript [ ] ) ?? [ ] , [ scriptsData ?. scripts ] ) ;
164164 const stats = statsData ?. stats ;
165165
166166 // Function to fetch container statuses
167- const fetchContainerStatuses = ( ) => {
167+ const fetchContainerStatuses = useCallback ( ( ) => {
168168 console . log ( 'Fetching container statuses...' , { scriptsCount : scripts . length } ) ;
169169 const containersWithIds = scripts
170170 . filter ( script => script . container_id )
@@ -185,7 +185,7 @@ export function InstalledScriptsTab() {
185185 if ( containersWithIds . length > 0 ) {
186186 containerStatusMutation . mutate ( { containers : containersWithIds } ) ;
187187 }
188- } ;
188+ } , [ scripts , containerStatusMutation ] ) ;
189189
190190 // Run cleanup when component mounts and scripts are loaded (only once)
191191 useEffect ( ( ) => {
@@ -203,7 +203,7 @@ export function InstalledScriptsTab() {
203203 const interval = setInterval ( fetchContainerStatuses , 60000 ) ; // Every 60 seconds
204204 return ( ) => clearInterval ( interval ) ;
205205 }
206- } , [ scripts . length ] ) ;
206+ } , [ scripts . length , fetchContainerStatuses ] ) ;
207207
208208 // Trigger status check when component becomes visible (tab is active)
209209 useEffect ( ( ) => {
@@ -215,20 +215,20 @@ export function InstalledScriptsTab() {
215215
216216 return ( ) => clearTimeout ( timeoutId ) ;
217217 }
218- } , [ ] ) ; // Empty dependency array means this runs on mount
218+ } , [ scripts . length , fetchContainerStatuses ] ) ; // Include dependencies
219219
220220 // Also trigger status check when scripts data loads
221221 useEffect ( ( ) => {
222222 if ( scripts . length > 0 && ! isLoading ) {
223223 console . log ( 'Scripts data loaded, triggering status check' ) ;
224224 fetchContainerStatuses ( ) ;
225225 }
226- } , [ scriptsData , isLoading ] ) ;
226+ } , [ scriptsData , isLoading , scripts . length , fetchContainerStatuses ] ) ;
227227
228228 // Update scripts with container statuses
229229 const scriptsWithStatus = scripts . map ( script => ( {
230230 ...script ,
231- container_status : script . container_id ? containerStatuses [ script . container_id ] || 'unknown' : undefined
231+ container_status : script . container_id ? containerStatuses [ script . container_id ] ?? 'unknown' : undefined
232232 } ) ) ;
233233
234234 // Filter and sort scripts
0 commit comments