fix: prevent sync banner from flashing on session switches

Added isFirstConnectRef to distinguish between first SSE connection
(page load) and subsequent reconnects (session switches). Only the
first connection forces the banner to show; subsequent connects use
non-forced mode which only displays the banner when returning from
background within 30s, eliminating unwanted banner flashes on
session changes.
This commit is contained in:
weishu
2025-12-24 15:10:00 +08:00
parent 3e4b8ddc64
commit baaf02daf5
+11 -1
View File
@@ -88,11 +88,21 @@ export function App() {
const selectedSessionId = sessionMatch ? sessionMatch.sessionId : null
const { isSyncing, startSync, endSync } = useSyncingState()
const syncTokenRef = useRef(0)
const isFirstConnectRef = useRef(true)
const handleSseConnect = useCallback(() => {
// Increment token to track this specific connection
const token = ++syncTokenRef.current
startSync({ force: true })
// Only force show banner on first connect (page load)
// Subsequent connects (session switches) use non-forced mode
// which only shows banner when returning from background
if (isFirstConnectRef.current) {
isFirstConnectRef.current = false
startSync({ force: true })
} else {
startSync()
}
const invalidations = [
queryClient.invalidateQueries({ queryKey: queryKeys.sessions }),
...(selectedSessionId ? [