mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 17:26:42 +00:00
Fix async update localize (#16667)
This commit is contained in:
parent
26d4839dfd
commit
4b7a517d98
@ -53,6 +53,8 @@ interface LoadedTranslationCategory {
|
|||||||
configFlow: boolean;
|
configFlow: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let updateResourcesIteration = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* superClass needs to contain `this.hass` and `this._updateHass`.
|
* superClass needs to contain `this.hass` and `this._updateHass`.
|
||||||
*/
|
*/
|
||||||
@ -362,6 +364,9 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _updateResources(language: string, data: any) {
|
private async _updateResources(language: string, data: any) {
|
||||||
|
updateResourcesIteration++;
|
||||||
|
const i = updateResourcesIteration;
|
||||||
|
|
||||||
// Update the language in hass, and update the resources with the newly
|
// Update the language in hass, and update the resources with the newly
|
||||||
// loaded resources. This merges the new data on top of the old data for
|
// loaded resources. This merges the new data on top of the old data for
|
||||||
// this language, so that the full translation set can be loaded across
|
// this language, so that the full translation set can be loaded across
|
||||||
@ -394,11 +399,17 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
|||||||
|
|
||||||
const localize = await computeLocalize(this, language, resources);
|
const localize = await computeLocalize(this, language, resources);
|
||||||
|
|
||||||
if (language === (this.hass ?? this._pendingHass).language) {
|
if (
|
||||||
this._updateHass({
|
updateResourcesIteration !== i ||
|
||||||
localize,
|
language !== (this.hass ?? this._pendingHass).language
|
||||||
});
|
) {
|
||||||
|
// if a new iteration has started or the language changed, abort
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._updateHass({
|
||||||
|
localize,
|
||||||
|
});
|
||||||
fireEvent(this, "translations-updated");
|
fireEvent(this, "translations-updated");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user