Show error empty state when the frontend can't authenticate - #5371
Merged
Conversation
The frontend asks the app for an access token before it can connect. When that request keeps failing - e.g. the server is only reachable on the local network and macOS denied the "Local Network" privacy permission - the page itself has already loaded, so there is no navigation error, and the frontend never reports a connection state. Nothing took the stand-by loader down and the app appeared to load forever, with no way to reach the error details. Report those failures to the web view controller so they are treated like a failed load: the error is kept for the details screen and the disconnected empty state (with "More details") shows after the usual grace period. The Alamofire session-task wrapper is unwrapped so the details screen shows the actionable URLError instead of the transport wrapper. This was most visible on Mac, where the stand-by loader's delayed settings and clean-cache escape hatches are hidden. Also drop the platform button style from ExternalLinkButton/ActionLinkButton: the rows draw their own background, so on Mac Catalyst the bordered style painted a second background inside each row.
Contributor
There was a problem hiding this comment.
Pull request overview
Ensures the app exits the stand-by loader and presents the disconnected empty state (with retained error details) when the frontend can’t obtain an access token (e.g., blocked local-network access), plus fixes Mac Catalyst row background styling for external/action link buttons.
Changes:
- Add
handleExternalAuthFailure(error:)toWebViewControllerProtocoland wire it fromWebViewScriptMessageHandlertoken-fetch failures. - Centralize empty-state grace-period scheduling via
scheduleEmptyStateAfterGracePeriod()and reuse it for connection-state updates and external-auth failures. - Update
ExternalLinkButton/ActionLinkButtonto use.buttonStyle(.plain)andforegroundStyleto avoid double backgrounds on Mac Catalyst.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/App/WebView/WebViewControllerTests.swift | Adds unit tests covering external-auth failure behavior (state, error preservation, timer arming, retry behavior). |
| Tests/App/WebView/Mocks/MockWebViewController.swift | Extends mock to satisfy the updated WebViewControllerProtocol and capture external-auth failures. |
| Sources/HADesignSystem/Sources/Components/ExternalLinkButton.swift | Removes platform button styling artifacts on Mac Catalyst and updates styling to avoid stacked backgrounds. |
| Sources/App/Frontend/WebView/WebViewController/WebViewControllerProtocol.swift | Adds a protocol hook for external-auth failures. |
| Sources/App/Frontend/WebView/WebViewController/WebViewController+ProtocolConformance.swift | Reuses the new grace-period scheduler for disconnected/unknown connection states. |
| Sources/App/Frontend/WebView/WebViewController/WebViewController+EmptyState.swift | Implements external-auth failure handling and factors out grace-period scheduling + error unwrapping. |
| Sources/App/Frontend/Extensions/WebViewScriptMessageHandler.swift | Calls into the web view controller on getExternalAuth promise rejection so the UI can surface the failure. |
Contributor
|
Found 5 unused localization strings in the codebase. Click to see detailsTo remove them, run the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AI Policy
Select exactly one option that describes AI usage in this contribution:
Summary
When the frontend page loads from cache but the app can't hand it an access token (e.g. the server is only reachable on the local network and macOS denied the "Local Network" permission), there is no navigation error and the frontend never reports a connection state. Nothing took the stand-by loader down, so the app just kept loading forever with no way to reach the error details.
Those token failures are now treated like a failed load: the error is kept for the details screen and the disconnected empty state with "More details" shows after the usual grace period.
Also drops the platform button style from the error details link rows, which draw their own background and so showed two stacked backgrounds on Mac.
Screenshots
Link to pull request in Documentation repository
Documentation: home-assistant/companion.home-assistant#
Any other notes
Most visible on Mac, where the stand-by loader's delayed settings and clean-cache escape hatches are hidden.
Generated by Claude Code