Fix race in translations loading (#9499)

This commit is contained in:
Bram Kragten 2021-07-05 11:05:49 +02:00 committed by GitHub
parent 2a1e31b5e9
commit 18996535b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -126,7 +126,7 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
this._applyTranslations(this.hass!);
}
protected panelUrlChanged(newPanelUrl) {
protected panelUrlChanged(newPanelUrl: string) {
super.panelUrlChanged(newPanelUrl);
// this may be triggered before hassConnected
this._loadFragmentTranslations(
@ -339,13 +339,16 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
...data,
},
};
const changes: Partial<HomeAssistant> = {
resources,
localize: await computeLocalize(this, language, resources),
};
// Update resources immediately, so when a new update comes in we don't miss values
this._updateHass({ resources });
const localize = await computeLocalize(this, language, resources);
if (language === (this.hass ?? this._pendingHass).language) {
this._updateHass(changes);
this._updateHass({
localize,
});
}
}