From 932cb033e6d96be91d491f172e4d2e7143f7db54 Mon Sep 17 00:00:00 2001 From: Srujan Gaddam <58529443+srujzs@users.noreply.github.com> Date: Mon, 21 Jul 2025 10:40:57 -0700 Subject: [PATCH] Use baseUri always when doing a hot reload or hot restart (#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: https://github.com/dart-lang/webdev/pull/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. --- .../flutter_tools/lib/src/isolated/devfs_web.dart | 4 ++-- .../lib/src/isolated/web_asset_server.dart | 12 ++++++------ packages/flutter_tools/lib/src/web/bootstrap.dart | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/flutter_tools/lib/src/isolated/devfs_web.dart b/packages/flutter_tools/lib/src/isolated/devfs_web.dart index cebd4a83c48..7646096f44c 100644 --- a/packages/flutter_tools/lib/src/isolated/devfs_web.dart +++ b/packages/flutter_tools/lib/src/isolated/devfs_web.dart @@ -202,7 +202,7 @@ class WebDevFS implements DevFS { Set get assetPathsToEvict => const {}; @override - Uri? get baseUri => webAssetServer.baseUri; + Uri get baseUri => webAssetServer.baseUri; @override Future create() async { @@ -234,7 +234,7 @@ class WebDevFS implements DevFS { platform: platform, shouldEnableMiddleware: shouldEnableMiddleware, ); - return baseUri!; + return baseUri; } @override diff --git a/packages/flutter_tools/lib/src/isolated/web_asset_server.dart b/packages/flutter_tools/lib/src/isolated/web_asset_server.dart index 982240a2098..e8cc9127712 100644 --- a/packages/flutter_tools/lib/src/isolated/web_asset_server.dart +++ b/packages/flutter_tools/lib/src/isolated/web_asset_server.dart @@ -122,7 +122,7 @@ class WebAssetServer implements AssetReader { } if (writeRestartScripts) { final srcIdsList = >[ - for (final String src in modules) {'src': src, 'id': src}, + for (final String src in modules) {'src': '$baseUri/$src', 'id': src}, ]; writeFile('restart_scripts.json', json.encode(srcIdsList)); } @@ -161,7 +161,7 @@ class WebAssetServer implements AssetReader { as Map, ); final List libraries = metadata.libraries.keys.toList(); - final moduleUri = baseUri != null ? '$baseUri/$module' : module; + final moduleUri = '$baseUri/$module'; moduleToLibrary.add({ 'src': moduleUri, 'module': metadata.name, @@ -176,8 +176,8 @@ class WebAssetServer implements AssetReader { return _webMemoryFS.write(codeFile, manifestFile, sourcemapFile, metadataFile); } - Uri? get baseUri => _baseUri; - Uri? _baseUri; + Uri get baseUri => _baseUri; + late Uri _baseUri; /// Start the web asset server on a [hostname] and [port]. /// @@ -351,8 +351,8 @@ class WebAssetServer implements AssetReader { ), ), packageConfigPath: buildInfo.packageConfigPath, - hotReloadSourcesUri: server._baseUri!.replace( - pathSegments: List.from(server._baseUri!.pathSegments) + hotReloadSourcesUri: server._baseUri.replace( + pathSegments: List.from(server._baseUri.pathSegments) ..add(_reloadScriptsFileName), ), ).strategy diff --git a/packages/flutter_tools/lib/src/web/bootstrap.dart b/packages/flutter_tools/lib/src/web/bootstrap.dart index 94d57748531..d2fa08a8965 100644 --- a/packages/flutter_tools/lib/src/web/bootstrap.dart +++ b/packages/flutter_tools/lib/src/web/bootstrap.dart @@ -267,7 +267,7 @@ $_simpleLoaderScript for (var i = 0; i < scripts.length; i++) { var script = scripts[i]; if (script.id == null) continue; - var src = _currentDirectory + script.src.toString(); + var src = script.src.toString(); var oldSrc = window.\$dartLoader.moduleIdToUrl.get(script.id); // We might actually load from a different uri, delete the old one