Skip to content
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

Merged
merged 3 commits into from Apr 10, 2020
Merged

Reload frontend if backend changes #5489

merged 3 commits into from Apr 10, 2020

Conversation

balloob
Copy link
Member

@balloob balloob commented Apr 7, 2020

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

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

// Force a reload if we reconnect to a new version so we load
// latest frontend.
conn.addEventListener("ready", (conn2) => {
if (conn2.haVersion !== curVersion) {
Copy link
Member

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?

Copy link
Member Author

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.

@balloob
Copy link
Member Author

balloob commented Apr 8, 2020

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;
Copy link
Member

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) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
navigator.serviceWorker.getRegistration().then((registration) => {
navigator.serviceWorker.ready.then((registration) => {

Copy link
Member Author

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.

@bramkragten bramkragten merged commit 0c1714e into dev Apr 10, 2020
@bramkragten bramkragten deleted the reload-new-backend branch April 10, 2020 09:55
@bramkragten bramkragten mentioned this pull request Apr 14, 2020
@lock lock bot locked and limited conversation to collaborators Apr 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants