Fix history/sensor cards stuck loading after backend restart#51531
Open
RaHehl wants to merge 3 commits intohome-assistant:devfrom
Open
Fix history/sensor cards stuck loading after backend restart#51531RaHehl wants to merge 3 commits intohome-assistant:devfrom
RaHehl wants to merge 3 commits intohome-assistant:devfrom
Conversation
- Add { resubscribe: false } to history subscriptions to prevent
corrupt HistoryStream state on auto-resubscription
- Add connection-status handlers to re-subscribe on reconnect
- Add sentinel pattern to prevent re-entrant async subscriptions
- Add shouldUpdate/updated retry when components become available
- Clear sensor device classes cache on WS error
- Clear _error on reconnect so cards can retry
- Add .catch() on unsubscribe to handle dead subscriptions
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes history-based UI (Lovelace history graph card, map card history paths, graph header/footer, and more-info history) getting stuck in a loading state after a backend restart by making history stream subscriptions reconnect-safe and adding retry logic when components become available.
Changes:
- Disable WebSocket auto-resubscription for history streams to avoid
HistoryStreaminternal state corruption. - Add reconnect (
connection-status) handling + retry-on-components-available logic to affected cards/dialogs, plus a sentinel pattern to prevent re-entrant async subscription races. - Improve resiliency by clearing the sensor numeric device class cache on WS errors and swallowing unsubscribe failures from dead server-side subscriptions.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/panels/lovelace/header-footer/hui-graph-header-footer.ts | Reconnect-driven unsubscribe/resubscribe, retry on component availability, and safer unsubscribe handling. |
| src/panels/lovelace/cards/hui-map-card.ts | Allow updates when component list changes, reconnect-driven resubscribe, and safer unsubscribe handling. |
| src/panels/lovelace/cards/hui-history-graph-card.ts | Sentinel anti-reentrancy for async subscribe, reconnect-driven resubscribe, component-availability retry, and safer unsubscribe handling. |
| src/panels/history/ha-panel-history.ts | Safer unsubscribe handling (but now impacted by global history resubscribe change). |
| src/dialogs/more-info/ha-more-info-history.ts | Reconnect-driven resubscribe/reset, component-availability retry, sentinel anti-reentrancy, and safer unsubscribe handling. |
| src/data/sensor.ts | Clear getSensorNumericDeviceClasses cache on WS error so retries can succeed. |
| src/data/history.ts | Disable auto-resubscription for history stream subscriptions (resubscribe: false). |
…tory panel - Use HASSDomEvent<ConnectionStatus> instead of (ev as CustomEvent).detail for proper type safety on all connection-status handlers - Add connection-status handler to ha-panel-history so it re-subscribes after backend restart (addresses concern about resubscribe: false)
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.
Breaking change
Proposed change
After a backend restart, history graph cards, map cards with history paths, graph header/footers, and the more-info history dialog would get stuck in a loading state and never recover without a full page refresh.
This happened because of a 3-part failure:
HistoryStreamobject holds mutable internal state that becomes corrupt when resubscribed with stale data.isComponentLoaded("history")which returnsfalsebecause the full component list hasn't arrived yet.shouldUpdate()blocks hass-only updates, soupdated()never fires to retry the subscription when components become available.This PR fixes all three issues:
{ resubscribe: false }to history stream subscriptions to prevent corrupt auto-resubscriptionconnection-statusevent handlers to all affected components to cleanly re-subscribe on reconnectshouldUpdate/updated/willUpdateto subscribe once the history component becomes available.catch()to unsubscribe calls to handle dead server-side subscriptions gracefullyScreenshots
Type of change
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed:
To help with the load of incoming pull requests: