Fix streaming content disappearing on window switch and improve skills scanning
- Add useRef + visibilitychange/focus listener to re-sync streaming content when Electron window regains focus, preventing blank content flash - Remove duplicate text SSE events from assistant handler (stream_event already provides real-time deltas) - Make skills scanner recursive to find commands in subdirectories - Add debug logging for skills directory resolution Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
fab8b41966
commit
a5e9fc76a8
3 files changed
+59
-15
No files matched your search
@@ -66,6 +66,25 @@ export function ChatView({ sessionId, initialMessages = [], modelName, initialMo
|
||||
}
|
||||
}, [sessionId, setWorkingDirectory, setPanelOpen]);
|
||||
|
||||
// Ref to keep accumulated streaming content in sync regardless of React batching
|
||||
const accumulatedRef = useRef('');
|
||||
|
||||
// Re-sync streaming content when the window regains visibility (Electron/browser tab switch)
|
||||
useEffect(() => {
|
||||
const handleVisibilityChange = () => {
|
||||
if (document.visibilityState === 'visible' && accumulatedRef.current) {
|
||||
setStreamingContent(accumulatedRef.current);
|
||||
}
|
||||
};
|
||||
document.addEventListener('visibilitychange', handleVisibilityChange);
|
||||
// Also handle Electron-specific focus events
|
||||
window.addEventListener('focus', handleVisibilityChange);
|
||||
return () => {
|
||||
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
||||
window.removeEventListener('focus', handleVisibilityChange);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const initializedRef = useRef(false);
|
||||
useEffect(() => {
|
||||
if (initialMessages.length > 0 && !initializedRef.current) {
|
||||
@@ -138,6 +157,7 @@ export function ChatView({ sessionId, initialMessages = [], modelName, initialMo
|
||||
setIsStreaming(true);
|
||||
setStreamingSessionId(sessionId);
|
||||
setStreamingContent('');
|
||||
accumulatedRef.current = '';
|
||||
setToolUses([]);
|
||||
setToolResults([]);
|
||||
setStatusText(undefined);
|
||||
@@ -185,6 +205,7 @@ export function ChatView({ sessionId, initialMessages = [], modelName, initialMo
|
||||
switch (event.type) {
|
||||
case 'text': {
|
||||
accumulated += event.data;
|
||||
accumulatedRef.current = accumulated;
|
||||
setStreamingContent(accumulated);
|
||||
break;
|
||||
}
|
||||
@@ -289,6 +310,7 @@ export function ChatView({ sessionId, initialMessages = [], modelName, initialMo
|
||||
|
||||
case 'error': {
|
||||
accumulated += '\n\n**Error:** ' + event.data;
|
||||
accumulatedRef.current = accumulated;
|
||||
setStreamingContent(accumulated);
|
||||
break;
|
||||
}
|
||||
@@ -346,6 +368,7 @@ export function ChatView({ sessionId, initialMessages = [], modelName, initialMo
|
||||
setIsStreaming(false);
|
||||
setStreamingSessionId('');
|
||||
setStreamingContent('');
|
||||
accumulatedRef.current = '';
|
||||
setToolUses([]);
|
||||
setToolResults([]);
|
||||
setStreamingToolOutput('');
|
||||
|
||||
Reference in new issue
Block a user