diff --git a/devtools/client/responsive.html/index.js b/devtools/client/responsive.html/index.js
index 64a14c021a73..b85c84d1d2db 100644
--- a/devtools/client/responsive.html/index.js
+++ b/devtools/client/responsive.html/index.js
@@ -47,6 +47,7 @@ let bootstrap = {
});
let provider = createElement(Provider, { store }, app);
ReactDOM.render(provider, document.querySelector("#root"));
+ this.initDevices();
window.postMessage({ type: "init" }, "*");
},
@@ -62,9 +63,28 @@ let bootstrap = {
* to dispatch. They can do so here.
*/
dispatch(action) {
+ if (!this.store) {
+ // If actions are dispatched after store is destroyed, ignore them. This
+ // can happen in tests that close the tool quickly while async tasks like
+ // initDevices() below are still pending.
+ return;
+ }
this.store.dispatch(action);
},
+ initDevices() {
+ GetDevices().then(devices => {
+ for (let type of devices.TYPES) {
+ this.dispatch(addDeviceType(type));
+ for (let device of devices[type]) {
+ if (device.os != "fxos") {
+ this.dispatch(addDevice(device, type));
+ }
+ }
+ }
+ });
+ },
+
};
window.addEventListener("load", function onLoad() {
@@ -92,18 +112,6 @@ Object.defineProperty(window, "store", {
window.addInitialViewport = contentURI => {
try {
bootstrap.dispatch(changeLocation(contentURI));
-
- GetDevices().then(devices => {
- for (let type of devices.TYPES) {
- bootstrap.dispatch(addDeviceType(type));
- for (let device of devices[type]) {
- if (device.os != "fxos") {
- bootstrap.dispatch(addDevice(device, type));
- }
- }
- }
- });
-
bootstrap.dispatch(addViewport());
} catch (e) {
console.error(e);
diff --git a/devtools/client/responsive.html/test/browser/head.js b/devtools/client/responsive.html/test/browser/head.js
index 246d66a16d00..54680f4505b9 100644
--- a/devtools/client/responsive.html/test/browser/head.js
+++ b/devtools/client/responsive.html/test/browser/head.js
@@ -16,6 +16,8 @@ Services.scriptloader.loadSubScript(
const TEST_URI_ROOT = "http://example.com/browser/devtools/client/responsive.html/test/browser/";
+SimpleTest.requestCompleteLog();
+
DevToolsUtils.testing = true;
Services.prefs.setCharPref("devtools.devices.url",
TEST_URI_ROOT + "devices.json");