Spaces:
Running

axeronis commited on
Commit
0efd976
·
1 Parent(s): 44051f4

fix: resolve toggle jitter by ignoring prop updates during active toggle operation

Browse files
Files changed (1) hide show
  1. frontend/components/ChatWindow.tsx +4 -1
frontend/components/ChatWindow.tsx CHANGED
@@ -113,6 +113,9 @@ export function ChatWindow({
113
 
114
  // Sync local state with props
115
  useEffect(() => {
 
 
 
116
  // Determine the next state based on available data
117
  let nextValue: boolean | undefined = undefined
118
 
@@ -128,7 +131,7 @@ export function ChatWindow({
128
  if (nextValue !== undefined && nextValue !== localAIActive) {
129
  setLocalAIActive(nextValue)
130
  }
131
- }, [conversation?.human_takeover, lead?.human_takeover, isConversationStale])
132
  const allMessages = [...messages, ...optimisticMessages, ...realtimeMessages]
133
  .filter((msg, index, self) => index === self.findIndex((t) => t.id === msg.id))
134
  .sort((a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime())
 
113
 
114
  // Sync local state with props
115
  useEffect(() => {
116
+ // GUARD: If we are currently toggling, ignore incoming prop updates to prevent jitter/ping-pong
117
+ if (isTogglingAI) return
118
+
119
  // Determine the next state based on available data
120
  let nextValue: boolean | undefined = undefined
121
 
 
131
  if (nextValue !== undefined && nextValue !== localAIActive) {
132
  setLocalAIActive(nextValue)
133
  }
134
+ }, [conversation?.human_takeover, lead?.human_takeover, isConversationStale, isTogglingAI])
135
  const allMessages = [...messages, ...optimisticMessages, ...realtimeMessages]
136
  .filter((msg, index, self) => index === self.findIndex((t) => t.id === msg.id))
137
  .sort((a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime())