From cdd4b052f984970e17be81ed24986f09d25e80f3 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 30 Oct 2024 15:20:44 +0100 Subject: [PATCH] Don't initialize `L10n.#elements` eagerly since it's unused in MOZCENTRAL builds It's not necessary to manually start translation in the Firefox PDF Viewer, and doing so would even cause problems there (see issue 17142). --- web/l10n.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/web/l10n.js b/web/l10n.js index bd348753d1596..053614e9885c7 100644 --- a/web/l10n.js +++ b/web/l10n.js @@ -23,7 +23,7 @@ class L10n { #dir; - #elements = new Set(); + #elements; #lang; @@ -71,7 +71,7 @@ class L10n { /** @inheritdoc */ async translate(element) { - this.#elements.add(element); + (this.#elements ||= new Set()).add(element); try { this.#l10n.connectRoot(element); await this.#l10n.translateRoots(); @@ -91,10 +91,13 @@ class L10n { /** @inheritdoc */ async destroy() { - for (const element of this.#elements) { - this.#l10n.disconnectRoot(element); + if (this.#elements) { + for (const element of this.#elements) { + this.#l10n.disconnectRoot(element); + } + this.#elements.clear(); + this.#elements = null; } - this.#elements.clear(); this.#l10n.pauseObserving(); }