Move DWDS initialization into the onLoadEndCallback for the DDC library bundle format (#163338)
The existing code assumed that DWDS needed to initialize some of the JS state between adding all the scripts to queue and when they are loaded. A closer examination of the existing AMD module format bootstrapper shows that we already only initialize DWDS' JS state after all the scripts are loaded. This is because it waits for the entrypoint to be loaded before initializing that state, and the entrypoint is only loaded after all its dependencies are loaded, which includes the SDK and transitively every file in the app. Since it's simpler and avoids the double-gating to call main, this change moves that initialization to after all the scripts are loaded and aligns with the AMD module bootstrapper. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
This commit is contained in:
parent
92281aae46
commit
87196771eb
@ -523,39 +523,27 @@ String generateDDCLibraryBundleMainModule({
|
||||
dartDevEmbedder.debugger.registerDevtoolsFormatter();
|
||||
|
||||
// Set up a final script that lets us know when all scripts have been loaded.
|
||||
// Only then can we call the main method.
|
||||
let onLoadEndSrc = '$onLoadEndBootstrap';
|
||||
window.\$dartLoader.loadConfig.bootstrapScript = {
|
||||
src: onLoadEndSrc,
|
||||
id: onLoadEndSrc,
|
||||
};
|
||||
window.\$dartLoader.loadConfig.tryLoadBootstrapScript = true;
|
||||
let dwdsCalledMain = false;
|
||||
let dartSrcsLoaded = false;
|
||||
let runMainWhenBoth = function() {
|
||||
// Only run once both all the scripts are loaded and DWDS triggers main.
|
||||
if (dwdsCalledMain && dartSrcsLoaded) {
|
||||
// Should be called by $onLoadEndBootstrap once all the scripts have been
|
||||
// loaded.
|
||||
window.$_onLoadEndCallback = function() {
|
||||
let child = {};
|
||||
child.main = function() {
|
||||
let sdkOptions = {
|
||||
nonNullAsserts: $nullAssertions,
|
||||
nativeNonNullAsserts: $nativeNullAssertions,
|
||||
};
|
||||
dartDevEmbedder.runMain(appName, sdkOptions);
|
||||
}
|
||||
/* MAIN_EXTENSION_MARKER */
|
||||
child.main();
|
||||
}
|
||||
// DWDS expects the main function to be lowercase.
|
||||
// TODO(srujzs): DWDS should be more robust to not have to require that.
|
||||
dwdsmain = function() {
|
||||
dwdsCalledMain = true;
|
||||
runMainWhenBoth();
|
||||
}
|
||||
// Should be called by $onLoadEndBootstrap once all the scripts have been
|
||||
// loaded.
|
||||
window.$_onLoadEndCallback = function() {
|
||||
dartSrcsLoaded = true;
|
||||
runMainWhenBoth();
|
||||
}
|
||||
|
||||
/* MAIN_EXTENSION_MARKER */
|
||||
dwdsmain();
|
||||
})();
|
||||
''';
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user