-
Notifications
You must be signed in to change notification settings - Fork 1
Bug #91: Blank panel on Translate without AI #18
Copy link
Copy link
Open
Labels
Description
Bug #91: Blank panel when tapping Translate without AI configured
Severity: Medium
Repro
- Ensure no AI API key is configured (or feature flag is off)
- Open any book → select text → tap "Translate" from edit menu
- Observe the AI panel
Expected
A clear error state or setup prompt: "Configure an AI provider in Settings to use translation."
Actual
The AI panel opens but shows a blank or unhelpful state. The .readerTranslateRequested notification fires, ensureAIReady() runs, but since isAIAvailable is false, the coordinator's setupIfNeeded() skips VM creation. The panel then renders with nil view models.
Root Cause
The Translate flow in ReaderContainerView.swift does:
.onReceive(.readerTranslateRequested) { notification in
ensureAIReady()
if let transVM = resolvedAICoordinator.translationViewModel {
transVM.originalText = info.selectedText
}
aiInitialTab = .translate
showAIPanel = true // ← opens panel regardless
}No guard prevents showAIPanel = true when AI is unavailable. The panel opens but has no view models to render content.
Proper Fix
Either:
- Guard before opening: Check
resolvedAICoordinator.isAIAvailablebefore settingshowAIPanel = true. Show an alert instead. - Panel handles gracefully:
AIReaderPanelalready has.featureDisabledstate with "Enable AI in Settings" message — ensure this state is reached when VMs are nil.
Files
vreader/Views/Reader/ReaderContainerView.swift— notification handler (lines 138-146)vreader/Views/Reader/ReaderContainerView+Sheets.swift— sheet builder checks for nil VMsvreader/Views/Reader/AIReaderPanel.swift— has.featureDisabledstate (lines 244-266) but may not be triggeredvreader/Services/AI/AIReaderAvailability.swift— availability checkvreader/Views/Reader/ReaderAICoordinator.swift—setupIfNeeded()skips when unavailable
Refs #6
Reactions are currently unavailable