Skip to content

Commit 628cc6f

Browse files
srujzsksokolovskyi
authored andcommitted
Use baseUri always when doing a hot reload or hot restart (flutter#172271)
We already use the baseUri when computing hot reload sources metadata as it can never be null. The member is changed to be non-nullable to reflect that. To be consistent, we also use the baseUri (full url) for a hot restart when running with the DDC library bundle format. Related PR: dart-lang/webdev#2650 ## 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]. - [ ] 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.
1 parent ec5b18b commit 628cc6f

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

packages/flutter_tools/lib/src/isolated/devfs_web.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class WebDevFS implements DevFS {
202202
Set<String> get assetPathsToEvict => const <String>{};
203203

204204
@override
205-
Uri? get baseUri => webAssetServer.baseUri;
205+
Uri get baseUri => webAssetServer.baseUri;
206206

207207
@override
208208
Future<Uri> create() async {
@@ -234,7 +234,7 @@ class WebDevFS implements DevFS {
234234
platform: platform,
235235
shouldEnableMiddleware: shouldEnableMiddleware,
236236
);
237-
return baseUri!;
237+
return baseUri;
238238
}
239239

240240
@override

packages/flutter_tools/lib/src/isolated/web_asset_server.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class WebAssetServer implements AssetReader {
122122
}
123123
if (writeRestartScripts) {
124124
final srcIdsList = <Map<String, String>>[
125-
for (final String src in modules) <String, String>{'src': src, 'id': src},
125+
for (final String src in modules) <String, String>{'src': '$baseUri/$src', 'id': src},
126126
];
127127
writeFile('restart_scripts.json', json.encode(srcIdsList));
128128
}
@@ -161,7 +161,7 @@ class WebAssetServer implements AssetReader {
161161
as Map<String, dynamic>,
162162
);
163163
final List<String> libraries = metadata.libraries.keys.toList();
164-
final moduleUri = baseUri != null ? '$baseUri/$module' : module;
164+
final moduleUri = '$baseUri/$module';
165165
moduleToLibrary.add(<String, Object>{
166166
'src': moduleUri,
167167
'module': metadata.name,
@@ -176,8 +176,8 @@ class WebAssetServer implements AssetReader {
176176
return _webMemoryFS.write(codeFile, manifestFile, sourcemapFile, metadataFile);
177177
}
178178

179-
Uri? get baseUri => _baseUri;
180-
Uri? _baseUri;
179+
Uri get baseUri => _baseUri;
180+
late Uri _baseUri;
181181

182182
/// Start the web asset server on a [hostname] and [port].
183183
///
@@ -351,8 +351,8 @@ class WebAssetServer implements AssetReader {
351351
),
352352
),
353353
packageConfigPath: buildInfo.packageConfigPath,
354-
hotReloadSourcesUri: server._baseUri!.replace(
355-
pathSegments: List<String>.from(server._baseUri!.pathSegments)
354+
hotReloadSourcesUri: server._baseUri.replace(
355+
pathSegments: List<String>.from(server._baseUri.pathSegments)
356356
..add(_reloadScriptsFileName),
357357
),
358358
).strategy

packages/flutter_tools/lib/src/web/bootstrap.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ $_simpleLoaderScript
267267
for (var i = 0; i < scripts.length; i++) {
268268
var script = scripts[i];
269269
if (script.id == null) continue;
270-
var src = _currentDirectory + script.src.toString();
270+
var src = script.src.toString();
271271
var oldSrc = window.\$dartLoader.moduleIdToUrl.get(script.id);
272272
273273
// We might actually load from a different uri, delete the old one

0 commit comments

Comments
 (0)