Open Bug 1530822 Opened 5 years ago Updated 2 years ago

netmonitor/src/api.js and all its dependencies are loaded twice in a row

Categories

(DevTools :: Netmonitor, defect, P3)

defect

Tracking

(Not tracked)

People

(Reporter: florian, Unassigned)

References

(Blocks 1 open bug)

Details

(Keywords: perf)

See this profile: http://bit.ly/2TiwR6J

This issue is about the devtools loaders, with an s, because we have two loaders in the game here.

We load the api module once from toolbox here:
https://searchfox.org/mozilla-central/source/devtools/client/framework/toolbox.js#60
This one load uses the DevTools loader. A loader that loads module once for all, and is never destroyed, nor attached to any particular context/document.

And we then load it from the netmonitor panel here:
https://searchfox.org/mozilla-central/source/devtools/client/netmonitor/initializer.js#19
This time this is loaded via the Browser loader instance of the netmonitor panel. This loader is very different as it is bound to the panel lifecycle. Whenever the panel is closed (when the toolbox closes), this loader will be destroyed. Also it is bound to the netmonitor document so that modules can have access to document and window globals. We typically use this loader for react modules which have to have access to the panel's document via globals.

This module is loaded via the browser loader from initializer based on the module location and the netmonitor browser loader parameters:
https://searchfox.org/mozilla-central/source/devtools/client/netmonitor/initializer.js#15

const require = window.windowRequire = BrowserLoader({
  baseURI: "resource://devtools/client/netmonitor/",
  window,
}).require;
const { NetMonitorAPI } = require("./src/api");

The baseURI parameter defines that all modules from this netmonitor folder will be loaded by the BrowserLoader, while any other one will be loaded via the DevTools loader.
(Well it is slightly more complex, as they is also this white list of folders to be going throught the browser loader:
https://searchfox.org/mozilla-central/source/devtools/client/shared/browser-loader.js#19-33)

So to address the issue here, we should either tune baseURI parameter and/or move api.js

Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.