t2ym/i18n-behavior

[Thin Syntax][Polymer 3.2.0+] Fail to access missing Class.prototype._fetchStatus object in thin syntax

t2ym opened this issue · 0 comments

t2ym commented

[Thin Syntax][Polymer 3.2.0+] Fail to access missing Class.prototype._fetchStatus object in thin syntax

Root Cause (Under Investigation)

  • In thin syntax, registered lifecycle callback fails to initialize Class.prototype._fetchStatus object by some reason under investigation

Reproducible Code

const $_documentContainer = document.createElement('template');
$_documentContainer.innerHTML = `<template id="simple-text-element">UI Text</template>`;
document.head.appendChild($_documentContainer.content);

Define = class SimpleTextElement extends BaseElements.I18nElement {
  static get importMeta() {
    return import.meta;
  }
};

Fix Candidate

  • Initialize _fetchStatus object if it is missing
  • After the root cause of the missing _fetchStatus is identified, this fix might be updated.
diff --git a/i18n-controller-core.js b/i18n-controller-core.js
index 0dc5a43b..18f58360 100644
--- a/i18n-controller-core.js
+++ b/i18n-controller-core.js
@@ -561,6 +561,18 @@ export const I18nControllerCoreMixin = {
     var id = (this.is || this.getAttribute('is')) === 'i18n-dom-bind' ? this.id : this.is;
     lang = lang || ''; // undefined and null are treated as default ''
     oldLang = oldLang || '';
+    if (!this._fetchStatus) {
+      this.constructor.prototype._fetchStatus = deepcopy({ // per custom element
+        fetchingInstance: null,
+        ajax: null,
+        ajaxLang: null,
+        lastLang: null,
+        fallbackLanguageList: null,
+        targetLang: null,
+        lastResponse: {},
+        rawResponses: {}
+      });
+    }
     if (lang !== oldLang &&
         bundles[oldLang] && bundles[oldLang][id]) {
       this._fetchStatus.lastLang = oldLang;

Note

  • This feature requires i18n-element/define-element.js but the fix is applied to i18n-behavior/i18n-controller-core.js