@@ -310,6 +310,7 @@ const SSEConnectionManager = ({ children }: { children: ReactNode }) => {
310310 const maxReconnectAttempts = 5
311311 let lastHeartbeat = Date . now ( ) ;
312312 let heartbeatCheckInterval : NodeJS . Timeout | null = null ;
313+ const isDebug = process . env . NEXT_PUBLIC_DEBUG === 'true' ;
313314
314315 const connect = ( ) => {
315316 try {
@@ -330,11 +331,13 @@ const SSEConnectionManager = ({ children }: { children: ReactNode }) => {
330331 setWorkerStatus ( payload as WorkerStatusSSEPayload ) ;
331332 } else if ( payload . type && typeof payload . status === 'boolean' ) {
332333 setWorkerStatus ( { type : payload . type as WorkerStatusType , status : payload . status } ) ;
333- } else {
334- console . warn ( "Received SSE message with unexpected payload format:" , payload ) ;
334+ } else if ( isDebug ) {
335+ console . warn ( "SSE: Unexpected payload format:" , payload ) ;
335336 }
336337 } catch ( e ) {
337- console . error ( "Failed to parse SSE message data:" , event . data , e ) ;
338+ if ( isDebug ) {
339+ console . error ( "SSE: Failed to parse message data:" , event . data , e ) ;
340+ }
338341 }
339342 } ;
340343
@@ -349,7 +352,9 @@ const SSEConnectionManager = ({ children }: { children: ReactNode }) => {
349352 } ) ;
350353
351354 eventSource . onerror = ( event ) => {
352- console . error ( `SSE connection error. Attempting to reconnect...` , event ) ;
355+ if ( isDebug ) {
356+ console . warn ( `SSE: Connection error, attempting to reconnect...` ) ;
357+ }
353358
354359 eventSource ?. close ( ) ;
355360
@@ -375,7 +380,9 @@ const SSEConnectionManager = ({ children }: { children: ReactNode }) => {
375380 heartbeatCheckInterval = setInterval ( ( ) => {
376381 const elapsed = Date . now ( ) - lastHeartbeat ;
377382 if ( elapsed > 90000 ) {
378- console . warn ( `SSE: No heartbeat in ${ Math . round ( elapsed / 1000 ) } s, reconnecting...` ) ;
383+ if ( isDebug ) {
384+ console . warn ( `SSE: No heartbeat in ${ Math . round ( elapsed / 1000 ) } s, reconnecting...` ) ;
385+ }
379386 eventSource ?. close ( ) ;
380387 reconnectAttempts = 0 ;
381388 connect ( ) ;
@@ -428,11 +435,15 @@ const SSEConnectionManager = ({ children }: { children: ReactNode }) => {
428435
429436 // Schedule refresh at 80% of remaining lifetime
430437 const refreshDelay = Math . round ( remainingMs * 0.8 ) ;
431- const refreshAt = new Date ( now + refreshDelay ) ;
432- console . log ( `SSE: Token expires at ${ new Date ( expiresAtMs ) . toISOString ( ) } , scheduling refresh in ${ Math . round ( refreshDelay / 1000 ) } s (at ${ refreshAt . toISOString ( ) } )` ) ;
438+ if ( process . env . NEXT_PUBLIC_DEBUG === 'true' ) {
439+ const refreshAt = new Date ( now + refreshDelay ) ;
440+ console . log ( `SSE: Token expires at ${ new Date ( expiresAtMs ) . toISOString ( ) } , scheduling refresh in ${ Math . round ( refreshDelay / 1000 ) } s (at ${ refreshAt . toISOString ( ) } )` ) ;
441+ }
433442
434443 const refreshTimer = setTimeout ( ( ) => {
435- console . log ( 'SSE: Proactive token refresh triggered' ) ;
444+ if ( process . env . NEXT_PUBLIC_DEBUG === 'true' ) {
445+ console . log ( 'SSE: Proactive token refresh triggered' ) ;
446+ }
436447 sendAuth ( { type : 'REFRESH' } ) ;
437448 } , refreshDelay ) ;
438449
0 commit comments