Skip to content

Commit 32c4ad1

Browse files
committed
Revert module tracking cleanup, address review comments, and clean up a TODO to remove a test
1 parent 06f64d3 commit 32c4ad1

File tree

5 files changed

+36
-48
lines changed

5 files changed

+36
-48
lines changed

dwds/test/common/chrome_proxy_service_common.dart

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,27 +2225,6 @@ void runTests({
22252225
);
22262226
});
22272227

2228-
test('reloadSources', () async {
2229-
final service = context.service;
2230-
final vm = await service.getVM();
2231-
final isolateId = vm.isolates!.first.id!;
2232-
final report = await service.reloadSources(isolateId);
2233-
// TODO(srujzs): This naturally fails regardless of the module format
2234-
// because we didn't set up prerequisite state (the reload scripts). We
2235-
// should create new tests for hot reload within DWDS and remove this
2236-
// test.
2237-
expect(report.success, false);
2238-
// Make sure that a notice was provided in the expected format.
2239-
final notices = report.json?['notices'];
2240-
expect(notices, isNotNull);
2241-
expect(notices is List, isTrue);
2242-
final noticeList = (notices as List).cast<Map>();
2243-
expect(noticeList, isNotEmpty);
2244-
final message = noticeList[0]['message'];
2245-
expect(message, isNotNull);
2246-
expect(message is String && message.isNotEmpty, isTrue);
2247-
});
2248-
22492228
test('setIsolatePauseMode', () async {
22502229
final service = context.service;
22512230
final vm = await service.getVM();

dwds/test/fixtures/context.dart

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,6 @@ class TestContext {
342342
hostname: _hostname,
343343
port: assetServerPort,
344344
index: filePathToServe,
345-
initialCompile: true,
346-
fullRestart: false,
347-
fileServerUri: null,
348345
);
349346

350347
if (testSettings.enableExpressionEvaluation) {
@@ -436,8 +433,8 @@ class TestContext {
436433

437434
// TODO(srujzs): In the case of the frontend server, it doesn't make sense
438435
// that we initialize a new HTTP server instead of reusing the one in
439-
// `TestAssetServer`. Why not just use that one? That seems to match with
440-
// what Flutter tools is doing.
436+
// `TestAssetServer`. We should instead use that one to align with Flutter
437+
// tools.
441438
_testServer = await TestServer.start(
442439
debugSettings: debugSettings.copyWith(
443440
expressionCompiler: expressionCompiler,
@@ -595,9 +592,7 @@ class TestContext {
595592
}
596593

597594
Future<void> recompile({required bool fullRestart}) async {
598-
await webRunner.run(
599-
frontendServerFileSystem,
600-
initialCompile: false,
595+
await webRunner.rerun(
601596
fullRestart: fullRestart,
602597
fileServerUri: Uri.parse('http://${testServer.host}:${testServer.port}'),
603598
);

frontend_server_common/lib/src/bootstrap.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,14 @@ $_simpleLoaderScript
504504
var script = scripts[i];
505505
if (script.id == null) continue;
506506
var src = script.src.toString();
507+
var oldSrc = window.\$dartLoader.moduleIdToUrl.get(script.id);
508+
509+
// We might actually load from a different uri, delete the old one
510+
// just to be sure.
511+
window.\$dartLoader.urlToModuleId.delete(oldSrc);
512+
513+
window.\$dartLoader.moduleIdToUrl.set(script.id, src);
514+
window.\$dartLoader.urlToModuleId.set(src, script.id);
507515
508516
numToLoad++;
509517

frontend_server_common/lib/src/devfs.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ class WebDevFS {
7878
required bool initialCompile,
7979
required bool fullRestart,
8080
// The uri of the `HttpServer` that handles file requests.
81-
// TODO(srujzs): This should be the same as the uri of the AssetServer, but
82-
// currently is not. Delete when that's fixed.
81+
// TODO(srujzs): This should be the same as the uri of the AssetServer to
82+
// align with Flutter tools, but currently is not. Delete when that's fixed.
8383
required Uri? fileServerUri,
8484
}) async {
8585
final mainPath = mainUri.toFilePath();

frontend_server_common/lib/src/resident_runner.dart

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,44 +66,50 @@ class ResidentWebRunner {
6666
ProjectFileInvalidator? _projectFileInvalidator;
6767
WebDevFS? devFS;
6868
Uri? uri;
69-
late Iterable<String> modules;
7069

7170
Future<int> run(
7271
FileSystem fileSystem, {
7372
String? hostname,
74-
int? port,
75-
String? index,
76-
required bool initialCompile,
77-
required bool fullRestart,
78-
// The uri of the `HttpServer` that handles file requests.
79-
// TODO(srujzs): This should be the same as the uri of the AssetServer, but
80-
// currently is not. Delete when that's fixed.
81-
required Uri? fileServerUri,
73+
required int port,
74+
required String index,
8275
}) async {
8376
_projectFileInvalidator ??= ProjectFileInvalidator(fileSystem: fileSystem);
8477
devFS ??= WebDevFS(
8578
fileSystem: fileSystem,
8679
hostname: hostname ?? 'localhost',
87-
port: port!,
80+
port: port,
8881
projectDirectory: projectDirectory,
8982
packageUriMapper: packageUriMapper,
90-
index: index!,
83+
index: index,
9184
urlTunneler: urlTunneler,
9285
sdkLayout: sdkLayout,
9386
compilerOptions: compilerOptions,
9487
);
9588
uri ??= await devFS!.create();
9689

9790
final report = await _updateDevFS(
98-
initialCompile: initialCompile,
99-
fullRestart: fullRestart,
100-
fileServerUri: fileServerUri);
91+
initialCompile: true, fullRestart: false, fileServerUri: null);
10192
if (!report.success) {
10293
_logger.severe('Failed to compile application.');
10394
return 1;
10495
}
10596

106-
modules = report.invalidatedModules!;
97+
generator.accept();
98+
return 0;
99+
}
100+
101+
Future<int> rerun(
102+
{required bool fullRestart,
103+
// The uri of the `HttpServer` that handles file requests.
104+
// TODO(srujzs): This should be the same as the uri of the AssetServer to
105+
// align with Flutter tools, but currently is not. Delete when that's fixed.
106+
required Uri fileServerUri}) async {
107+
final report = await _updateDevFS(
108+
initialCompile: false, fullRestart: fullRestart, fileServerUri: null);
109+
if (!report.success) {
110+
_logger.severe('Failed to compile application.');
111+
return 1;
112+
}
107113

108114
generator.accept();
109115
return 0;
@@ -113,8 +119,8 @@ class ResidentWebRunner {
113119
required bool initialCompile,
114120
required bool fullRestart,
115121
// The uri of the `TestServer` that handles file requests.
116-
// TODO(srujzs): This should be the same as the uri of the AssetServer, but
117-
// currently is not. Delete when that's fixed.
122+
// TODO(srujzs): This should be the same as the uri of the AssetServer to
123+
// align with Flutter tools, but currently is not. Delete when that's fixed.
118124
required Uri? fileServerUri,
119125
}) async {
120126
final invalidationResult = await _projectFileInvalidator!.findInvalidated(

0 commit comments

Comments
 (0)