From 83b466cacc7fa0f7e753fd2688915408b2674cc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Thu, 25 Jan 2024 14:57:04 +0100 Subject: [PATCH] only update if document lang or dir was changed --- .../localization-api/localization.manager.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/libs/localization-api/localization.manager.ts b/src/Umbraco.Web.UI.Client/src/libs/localization-api/localization.manager.ts index 31bd88ce99..b5b58c0fc9 100644 --- a/src/Umbraco.Web.UI.Client/src/libs/localization-api/localization.manager.ts +++ b/src/Umbraco.Web.UI.Client/src/libs/localization-api/localization.manager.ts @@ -78,18 +78,30 @@ export class UmbLocalizationManager { /** Updates all localized elements that are currently connected */ updateAll = () => { - this.documentDirection = document.documentElement.dir || 'ltr'; - this.documentLanguage = document.documentElement.lang || navigator.language; + const newDir = document.documentElement.dir || 'ltr'; + const newLang = document.documentElement.lang || navigator.language; + + if (this.documentDirection === newDir && this.documentLanguage === newLang) return; + + // The document direction or language did changed, so lets move on: + this.documentDirection = newDir; + this.documentLanguage = newLang; // Check if there was any changed. this.connectedControllers.forEach((ctrl) => { ctrl.documentUpdate(); }); + if (this.#requestUpdateChangedKeysId) { + cancelAnimationFrame(this.#requestUpdateChangedKeysId); + this.#requestUpdateChangedKeysId = undefined; + } this.#changedKeys.clear(); }; updateChangedKeys = () => { + this.#requestUpdateChangedKeysId = undefined; + this.connectedControllers.forEach((ctrl) => { ctrl.keysChanged(this.#changedKeys); });