Bug 1716664 - Skip applying translations on elements that had their data-l10n-id removed. r=platform-i18n-reviewers,dminor
authorZibi Braniecki <zbraniecki@mozilla.com>
Wed, 16 Jun 2021 01:13:17 +0000
changeset 583492 da56143c727af20bbcd4f3ccf8ecd4cc09a0920b
parent 583491 f155dce2913463e41a589af8eec1dbc24c42aac3
child 583493 802fef6188555fbda869d2c83a4b319b1d56c90b
push id145065
push userzbraniecki@mozilla.com
push dateWed, 16 Jun 2021 01:17:39 +0000
treeherderautoland@da56143c727a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersplatform-i18n-reviewers, dminor
bugs1716664
milestone91.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1716664 - Skip applying translations on elements that had their data-l10n-id removed. r=platform-i18n-reviewers,dminor Differential Revision: https://phabricator.services.mozilla.com/D117952
dom/l10n/DOMLocalization.cpp
--- a/dom/l10n/DOMLocalization.cpp
+++ b/dom/l10n/DOMLocalization.cpp
@@ -487,16 +487,23 @@ bool DOMLocalization::ApplyTranslations(
     // If we have a proto, we expect all elements are connected up.
     // If they're not, they may have been removed by earlier translations.
     // We will have added an error in L10nOverlays in this case.
     // This is an error in fluent use, but shouldn't be crashing. There's
     // also no point translating the element - skip it:
     if (aProto && !elem->IsInComposedDoc()) {
       continue;
     }
+
+    // It is possible that someone removed the `data-l10n-id` from the element
+    // before the async translation completed. In that case, skip applying
+    // the translation.
+    if (!elem->HasAttr(kNameSpaceID_None, nsGkAtoms::datal10nid)) {
+      continue;
+    }
     L10nOverlays::TranslateElement(*elem, aTranslations[i].Value(), errors,
                                    aRv);
     if (NS_WARN_IF(aRv.Failed())) {
       hasMissingTranslation = true;
       continue;
     }
     if (aProto) {
       // We only need to rebuild deep if the translation has a value.