Commit 1b7c1479 authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Chromium LUCI CQ

Files app: Fix race when initializing as JS modules

The i18n strings in the deferred elements need the `loadTimeData` which
is initialized in the background page and in the
initBackgroundPagePromise_.  Change the initialization for JS modules to
wait the background promise before importing the deferred elements.

Bug: 1133186
Change-Id: I2f82cc3ca89964900c5711652379fbcbdff17acb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2641785
Commit-Queue: Jeremie Boulic <jboulic@chromium.org>
Reviewed-by: default avatarJeremie Boulic <jboulic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845544}
parent e28a67dc
...@@ -2142,7 +2142,6 @@ js_modulizer("modulize") { ...@@ -2142,7 +2142,6 @@ js_modulizer("modulize") {
"cr.ui.MultiMenu|MultiMenu", "cr.ui.MultiMenu|MultiMenu",
"cr.ui.ComboButton|ComboButton", "cr.ui.ComboButton|ComboButton",
"cr.filebrowser.DefaultTaskDialog|DefaultTaskDialog", "cr.filebrowser.DefaultTaskDialog|DefaultTaskDialog",
"window.importElementsPromise|importElements",
] ]
} }
......
...@@ -24,3 +24,6 @@ export function importElements() { ...@@ -24,3 +24,6 @@ export function importElements() {
document.head.appendChild(script); document.head.appendChild(script);
}); });
} }
// TODO: Remove this initialization once non-JS module is removed.
window.importElements = importElements;
...@@ -874,8 +874,16 @@ ...@@ -874,8 +874,16 @@
this.document_ = this.dialogDom_.ownerDocument; this.document_ = this.dialogDom_.ownerDocument;
metrics.startInterval('Load.InitDocuments'); metrics.startInterval('Load.InitDocuments');
await Promise.all( if (window.importElementsPromise) {
[this.initBackgroundPagePromise_, window.importElementsPromise]); // For non-js modules version these promises can run in parallel.
await Promise.all(
[this.initBackgroundPagePromise_, window.importElementsPromise]);
} else if (window.importElements) {
// importElements depend on loadTimeData which is initialized in the
// initBackgroundPagePromise_.
await this.initBackgroundPagePromise_;
await window.importElements();
}
metrics.recordInterval('Load.InitDocuments'); metrics.recordInterval('Load.InitDocuments');
metrics.startInterval('Load.InitUI'); metrics.startInterval('Load.InitUI');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment