Skip to content

Commit de47795

Browse files
committed
Deduplicate showRetryBarrier computation in AIView
Compute showRetryBarrier once before early return, use for both keybinds and UI rendering. Eliminates duplicate hasInterruptedStream call.
1 parent c46a118 commit de47795

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/components/AIView.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,20 @@ const AIViewInner: React.FC<AIViewProps> = ({
205205
// eslint-disable-next-line react-hooks/exhaustive-deps
206206
}, [workspaceId, workspaceState?.loading]);
207207

208+
// Compute showRetryBarrier once for both keybinds and UI
209+
// Track if last message was interrupted or errored (for RetryBarrier)
210+
// Uses same logic as useResumeManager for DRY
211+
const showRetryBarrier = workspaceState
212+
? !workspaceState.canInterrupt &&
213+
hasInterruptedStream(workspaceState.messages, workspaceState.pendingStreamStartTime)
214+
: false;
215+
208216
// Handle keyboard shortcuts (using optional refs that are safe even if not initialized)
209217
useAIViewKeybinds({
210218
workspaceId,
211219
currentModel: workspaceState?.currentModel ?? null,
212220
canInterrupt: workspaceState?.canInterrupt ?? false,
213-
showRetryBarrier: workspaceState
214-
? !workspaceState.canInterrupt &&
215-
hasInterruptedStream(workspaceState.messages, workspaceState.pendingStreamStartTime)
216-
: false,
221+
showRetryBarrier,
217222
currentWorkspaceThinking,
218223
setThinkingLevel,
219224
setAutoRetry,
@@ -261,16 +266,11 @@ const AIViewInner: React.FC<AIViewProps> = ({
261266
}
262267

263268
// Extract state from workspace state
264-
const { messages, canInterrupt, isCompacting, loading, currentModel, pendingStreamStartTime } =
265-
workspaceState;
269+
const { messages, canInterrupt, isCompacting, loading, currentModel } = workspaceState;
266270

267271
// Get active stream message ID for token counting
268272
const activeStreamMessageId = aggregator.getActiveStreamMessageId();
269273

270-
// Track if last message was interrupted or errored (for RetryBarrier)
271-
// Uses same logic as useResumeManager for DRY
272-
const showRetryBarrier = !canInterrupt && hasInterruptedStream(messages, pendingStreamStartTime);
273-
274274
// Note: We intentionally do NOT reset autoRetry when streams start.
275275
// If user pressed Ctrl+C, autoRetry stays false until they manually retry.
276276
// This makes state transitions explicit and predictable.

0 commit comments

Comments
 (0)