Skip to content

Commit 9b94a5a

Browse files
authored
Updating DDC's bootstrapper for auto hot reload/restart. (#4300)
Synchronizes some logic with that of the rest of our ecosystem
1 parent 5fde5c9 commit 9b94a5a

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

build_web_compilers/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 4.4.5
2+
3+
- Updating DDC's bootstrapper to be consistent with the rest of the ecosystem.
4+
15
## 4.4.4
26

37
- Allow Dart SDK 3.11.x and 3.12 prerelease.

build_web_compilers/lib/src/dev_compiler_bootstrap.dart

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -793,40 +793,41 @@ $_simpleLoaderScript
793793
// We should have written a file containing all the scripts that need to be
794794
// reloaded into the page. This is then read when a hot restart is triggered
795795
// in DDC via the `\$dartReloadModifiedModules` callback.
796-
let restartScripts = _currentDirectory + 'restart_scripts.json';
796+
let reloadedSources = _currentDirectory + 'reloaded_sources.json';
797797
798798
if (!window.\$dartReloadModifiedModules) {
799799
window.\$dartReloadModifiedModules = (function(appName, callback) {
800-
var xhttp = new XMLHttpRequest();
800+
const xhttp = new XMLHttpRequest();
801801
xhttp.withCredentials = true;
802802
xhttp.onreadystatechange = function() {
803803
// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/readyState
804804
if (this.readyState == 4 && this.status == 200 || this.status == 304) {
805-
var scripts = JSON.parse(this.responseText);
806-
var numToLoad = 0;
807-
var numLoaded = 0;
808-
for (var i = 0; i < scripts.length; i++) {
809-
var script = scripts[i];
810-
if (script.id == null) continue;
811-
var src = script.src.toString();
812-
var oldSrc = window.\$dartLoader.moduleIdToUrl.get(script.id);
805+
const scripts = JSON.parse(this.responseText);
806+
let numToLoad = 0;
807+
let numLoaded = 0;
808+
for (let i = 0; i < scripts.length; i++) {
809+
const script = scripts[i];
810+
const module = script.module;
811+
if (module == null) continue;
812+
const src = script.src;
813+
const oldSrc = window.\$dartLoader.moduleIdToUrl.get(module);
813814
814815
// We might actually load from a different uri, delete the old one
815816
// just to be sure.
816817
window.\$dartLoader.urlToModuleId.delete(oldSrc);
817818
818-
window.\$dartLoader.moduleIdToUrl.set(script.id, src);
819-
window.\$dartLoader.urlToModuleId.set(src, script.id);
819+
window.\$dartLoader.moduleIdToUrl.set(module, src);
820+
window.\$dartLoader.urlToModuleId.set(src, module);
820821
821822
numToLoad++;
822823
823-
var el = document.getElementById(script.id);
824+
let el = document.getElementById(module);
824825
if (el) el.remove();
825826
el = window.\$dartCreateScript();
826827
el.src = policy.createScriptURL(src);
827828
el.async = false;
828829
el.defer = true;
829-
el.id = script.id;
830+
el.id = module;
830831
el.onload = function() {
831832
numLoaded++;
832833
if (numToLoad == numLoaded) callback();
@@ -837,7 +838,7 @@ $_simpleLoaderScript
837838
if (numToLoad == 0) callback();
838839
}
839840
};
840-
xhttp.open("GET", restartScripts, true);
841+
xhttp.open("GET", reloadedSources, true);
841842
xhttp.send();
842843
});
843844
}

build_web_compilers/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: build_web_compilers
2-
version: 4.4.4
2+
version: 4.4.5
33
description: Builder implementations wrapping the dart2js and DDC compilers.
44
repository: https://github.com/dart-lang/build/tree/master/build_web_compilers
55
resolution: workspace

0 commit comments

Comments
 (0)