New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reload frontend if backend changes #5489
Conversation
src/layouts/home-assistant.ts
Outdated
// Force a reload if we reconnect to a new version so we load | ||
// latest frontend. | ||
conn.addEventListener("ready", (conn2) => { | ||
if (conn2.haVersion !== curVersion) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be done in hassReconnected
in the connection-mixin
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh reconnected is a good one.
I didn't want to put it in the connection mixin because it's specific to the frontend, and I wouldn't want to add it into Cast.
Now made sure we also handle the case where we are loaded from a service worker. |
@@ -16,6 +19,7 @@ export class HomeAssistantAppEl extends HassElement { | |||
@property() private _route?: Route; | |||
@property() private _error = false; | |||
@property() private _panelUrl?: string; | |||
private _haVersion?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do we set this?
// If backend has been upgraded, make sure we update frontend | ||
if (this.hass!.connection.haVersion !== this._haVersion) { | ||
if (supportsServiceWorker()) { | ||
navigator.serviceWorker.getRegistration().then((registration) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
navigator.serviceWorker.getRegistration().then((registration) => { | |
navigator.serviceWorker.ready.then((registration) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to know if the worker is active. We just want to know if we have one, and if we have one, we want to tell the browser that it should update the worker.
Breaking change
Proposed change
We use code splitting to break up the frontend in pieces. If we update Home Assistant and the frontend is loaded, the frontend will try to load pieces that are no longer available, resulting in blank screens and errors.
With this fix, if the connection reconnects and discovers a change in Home Assistant version, reload the frontend.
Type of change
Example configuration
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed: