@@ -77,6 +77,7 @@ export function VersionDisplay() {
7777 const [ isNetworkError , setIsNetworkError ] = useState ( false ) ;
7878 const [ updateLogs , setUpdateLogs ] = useState < string [ ] > ( [ ] ) ;
7979 const [ shouldSubscribe , setShouldSubscribe ] = useState ( false ) ;
80+ const [ updateStartTime , setUpdateStartTime ] = useState < number | null > ( null ) ;
8081 const lastLogTimeRef = useRef < number > ( Date . now ( ) ) ;
8182 const reconnectIntervalRef = useRef < NodeJS . Timeout | null > ( null ) ;
8283
@@ -99,7 +100,7 @@ export function VersionDisplay() {
99100 } ) ;
100101
101102 // Poll for update logs
102- const { data : updateLogsData , refetch : refetchLogs } = api . version . getUpdateLogs . useQuery ( undefined , {
103+ const { data : updateLogsData } = api . version . getUpdateLogs . useQuery ( undefined , {
103104 enabled : shouldSubscribe ,
104105 refetchInterval : 1000 , // Poll every second
105106 refetchIntervalInBackground : true ,
@@ -126,18 +127,22 @@ export function VersionDisplay() {
126127 const checkInterval = setInterval ( ( ) => {
127128 const timeSinceLastLog = Date . now ( ) - lastLogTimeRef . current ;
128129
129- // If no logs for 3 seconds and we're updating, assume server is restarting
130- if ( timeSinceLastLog > 3000 && isUpdating ) {
130+ // Only start reconnection if we've been updating for at least 30 seconds
131+ // and no logs for 10 seconds (to avoid premature reconnection during npm install)
132+ const hasBeenUpdatingLongEnough = updateStartTime && ( Date . now ( ) - updateStartTime ) > 60000 ;
133+ const noLogsForAWhile = timeSinceLastLog > 40000 ;
134+
135+ if ( hasBeenUpdatingLongEnough && noLogsForAWhile && isUpdating ) {
131136 setIsNetworkError ( true ) ;
132137 setUpdateLogs ( prev => [ ...prev , 'Server restarting... waiting for reconnection...' ] ) ;
133138
134139 // Start trying to reconnect
135140 startReconnectAttempts ( ) ;
136141 }
137- } , 1000 ) ;
142+ } , 1500 ) ; // Check every 2 seconds instead of 1
138143
139144 return ( ) => clearInterval ( checkInterval ) ;
140- } , [ shouldSubscribe , isUpdating ] ) ;
145+ } , [ shouldSubscribe , isUpdating , updateStartTime ] ) ;
141146
142147 // Attempt to reconnect and reload page when server is back
143148 const startReconnectAttempts = ( ) => {
@@ -184,6 +189,7 @@ export function VersionDisplay() {
184189 setIsNetworkError ( false ) ;
185190 setUpdateLogs ( [ ] ) ;
186191 setShouldSubscribe ( false ) ;
192+ setUpdateStartTime ( Date . now ( ) ) ;
187193 lastLogTimeRef . current = Date . now ( ) ;
188194 executeUpdate . mutate ( ) ;
189195 } ;
0 commit comments