From 461b86a04b018de7ebe2208e756dd7387746056a Mon Sep 17 00:00:00 2001 From: Adam Ernst Date: Thu, 5 Nov 2020 11:47:09 -0600 Subject: [PATCH] Fix race condition in translation loading (#7597) --- src/state/translations-mixin.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/state/translations-mixin.ts b/src/state/translations-mixin.ts index 16e3abb5ac..72f07f2bdc 100644 --- a/src/state/translations-mixin.ts +++ b/src/state/translations-mixin.ts @@ -221,9 +221,15 @@ export default >(superClass: T) => // 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 // multiple fragments. + // + // Beware of a subtle race condition: it is possible to get here twice + // before this.hass is even created. In this case our base state comes + // from this._pendingHass instead. Otherwise the first set of strings is + // overwritten when we call _updateHass the second time! + const baseHass = this.hass ?? this._pendingHass; const resources = { [language]: { - ...this.hass?.resources?.[language], + ...baseHass?.resources?.[language], ...data, }, };