Fix side-effect instance constructions during module loading
While working on the linear memory inspector component
(https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2501301)
we discovered that both snippets and quick_open were side-effect
instantiating instances during module loading. This caused issues
when trying to write isolated unittests for other components, if
they were (transitively) importing these modules.
To resolve these issues, we defer creation to the appropriate time.
In the case of CommandMenu, this was a small refactoring to use
the instance-singleton-pattern we have been using throughout the
codebase.
For Snippets, it was less obvious. In the end, we realized that
the singleton instances that snippets/ was relying on were constructed
in `Main.MainImpl.MainImpl._createAppUI`. More specifically,
the instantiation of `self.Persistence.isolatedFileSystemManager`
right at the top of `_createAppUI` was implicitly required for
snippets/.
This wasn't a problem when loading DevTools, as we lazy-load snippets/
after we instantiate `MainImpl`. Hence, the singletons were in place
and the code would correctly function. However, that assumption is
invalid when loading `snippets/` in isolation, which was the case
when writing the unit test.
The same treatment was necessary for `Snippets.project`, which has
been moved to a lazily-computed function.
[email protected],[email protected],[email protected]
Fixed: 1143170
Change-Id: I28d3bbbc428f0316ca89453f98331b7479711c87
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2503953
Commit-Queue: Tim van der Lippe <[email protected]>
Reviewed-by: Paul Lewis <[email protected]>
Reviewed-by: Jack Franklin <[email protected]>
Reviewed-by: Kim-Anh Tran <[email protected]>
diff --git a/front_end/snippets/SnippetsQuickOpen.js b/front_end/snippets/SnippetsQuickOpen.js
index a22043c..f784b2e 100644
--- a/front_end/snippets/SnippetsQuickOpen.js
+++ b/front_end/snippets/SnippetsQuickOpen.js
@@ -7,7 +7,7 @@
import * as QuickOpen from '../quick_open/quick_open.js';
import * as Workspace from '../workspace/workspace.js'; // eslint-disable-line no-unused-vars
-import {evaluateScriptSnippet, project} from './ScriptSnippetFileSystem.js';
+import {evaluateScriptSnippet, findSnippetsProject} from './ScriptSnippetFileSystem.js';
export class SnippetsQuickOpen extends QuickOpen.FilteredListWidget.Provider {
constructor() {
@@ -40,7 +40,7 @@
* @override
*/
attach() {
- this._snippets = project.uiSourceCodes();
+ this._snippets = findSnippetsProject().uiSourceCodes();
}
/**