Skip to content

Commit 53c1af3

Browse files
committed
fix(App): wrap session handlers in useCallback to avoid warnings on depth
Wrap markSessionAsActive, markSessionAsInactive, markSessionAsProcessing, markSessionAsNotProcessing, and replaceTemporarySession functions in useCallback hooks to prevent unnecessary re-renders and stabilize function references across component lifecycle. This optimization ensures child components receiving these callbacks won't re-render unnecessarily when AppContent re-renders.
1 parent 1bc2cf4 commit 53c1af3

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

src/App.jsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Handles both existing sessions (with real IDs) and new sessions (with temporary IDs).
1919
*/
2020

21-
import React, { useState, useEffect } from 'react';
21+
import React, { useState, useEffect, useCallback } from 'react';
2222
import { BrowserRouter as Router, Routes, Route, useNavigate, useParams } from 'react-router-dom';
2323
import Sidebar from './components/Sidebar';
2424
import MainContent from './components/MainContent';
@@ -478,47 +478,47 @@ function AppContent() {
478478

479479
// markSessionAsActive: Called when user sends a message to mark session as protected
480480
// This includes both real session IDs and temporary "new-session-*" identifiers
481-
const markSessionAsActive = (sessionId) => {
481+
const markSessionAsActive = useCallback((sessionId) => {
482482
if (sessionId) {
483483
setActiveSessions(prev => new Set([...prev, sessionId]));
484484
}
485-
};
485+
}, []);
486486

487487
// markSessionAsInactive: Called when conversation completes/aborts to re-enable project updates
488-
const markSessionAsInactive = (sessionId) => {
488+
const markSessionAsInactive = useCallback((sessionId) => {
489489
if (sessionId) {
490490
setActiveSessions(prev => {
491491
const newSet = new Set(prev);
492492
newSet.delete(sessionId);
493493
return newSet;
494494
});
495495
}
496-
};
496+
}, []);
497497

498498
// Processing Session Functions: Track which sessions are currently thinking/processing
499499

500500
// markSessionAsProcessing: Called when Claude starts thinking/processing
501-
const markSessionAsProcessing = (sessionId) => {
501+
const markSessionAsProcessing = useCallback((sessionId) => {
502502
if (sessionId) {
503503
setProcessingSessions(prev => new Set([...prev, sessionId]));
504504
}
505-
};
505+
}, []);
506506

507507
// markSessionAsNotProcessing: Called when Claude finishes thinking/processing
508-
const markSessionAsNotProcessing = (sessionId) => {
508+
const markSessionAsNotProcessing = useCallback((sessionId) => {
509509
if (sessionId) {
510510
setProcessingSessions(prev => {
511511
const newSet = new Set(prev);
512512
newSet.delete(sessionId);
513513
return newSet;
514514
});
515515
}
516-
};
516+
}, []);
517517

518518
// replaceTemporarySession: Called when WebSocket provides real session ID for new sessions
519519
// Removes temporary "new-session-*" identifiers and adds the real session ID
520520
// This maintains protection continuity during the transition from temporary to real session
521-
const replaceTemporarySession = (realSessionId) => {
521+
const replaceTemporarySession = useCallback((realSessionId) => {
522522
if (realSessionId) {
523523
setActiveSessions(prev => {
524524
const newSet = new Set();
@@ -532,7 +532,7 @@ function AppContent() {
532532
return newSet;
533533
});
534534
}
535-
};
535+
}, []);
536536

537537
// Version Upgrade Modal Component
538538
const VersionUpgradeModal = () => {

0 commit comments

Comments
 (0)