diff --git a/packages/flutter_tools/lib/src/isolated/devfs_web.dart b/packages/flutter_tools/lib/src/isolated/devfs_web.dart index 64935b16f0..3d03483639 100644 --- a/packages/flutter_tools/lib/src/isolated/devfs_web.dart +++ b/packages/flutter_tools/lib/src/isolated/devfs_web.dart @@ -189,6 +189,8 @@ class WebAssetServer implements AssetReader { _hotRestartGeneration++; } + static const String _reloadScriptsFileName = 'reload_scripts.json'; + /// Given a list of [modules] that need to be reloaded, writes a file that /// contains a list of objects each with two fields: /// @@ -219,7 +221,7 @@ class WebAssetServer implements AssetReader { final List libraries = metadata.libraries.keys.toList(); moduleToLibrary.add({'src': module, 'libraries': libraries}); } - writeFile('reload_scripts.json', json.encode(moduleToLibrary)); + writeFile(_reloadScriptsFileName, json.encode(moduleToLibrary)); } @visibleForTesting @@ -227,6 +229,9 @@ class WebAssetServer implements AssetReader { return _webMemoryFS.write(codeFile, manifestFile, sourcemapFile, metadataFile); } + Uri? get baseUri => _baseUri; + Uri? _baseUri; + /// Start the web asset server on a [hostname] and [port]. /// /// If [testMode] is true, do not actually initialize dwds or the shelf static @@ -314,6 +319,15 @@ class WebAssetServer implements AssetReader { webRenderer: webRenderer, useLocalCanvasKit: useLocalCanvasKit, ); + final int selectedPort = server.selectedPort; + String url = '$hostname:$selectedPort'; + if (hostname == 'any') { + url = 'localhost:$selectedPort'; + } + server._baseUri = Uri.http(url, server.basePath); + if (tlsCertPath != null && tlsCertKeyPath != null) { + server._baseUri = Uri.https(url, server.basePath); + } if (testMode) { return server; } @@ -386,6 +400,10 @@ class WebAssetServer implements AssetReader { ), ), packageConfigPath: buildInfo.packageConfigPath, + hotReloadSourcesUri: server._baseUri!.replace( + pathSegments: List.from(server._baseUri!.pathSegments) + ..add(_reloadScriptsFileName), + ), ).strategy : FrontendServerRequireStrategyProvider( ReloadConfiguration.none, @@ -946,8 +964,7 @@ class WebDevFS implements DevFS { Set get assetPathsToEvict => const {}; @override - Uri? get baseUri => _baseUri; - Uri? _baseUri; + Uri? get baseUri => webAssetServer._baseUri; @override Future create() async { @@ -974,17 +991,7 @@ class WebDevFS implements DevFS { ddcModuleSystem: ddcModuleSystem, canaryFeatures: canaryFeatures, ); - - final int selectedPort = webAssetServer.selectedPort; - String url = '$hostname:$selectedPort'; - if (hostname == 'any') { - url = 'localhost:$selectedPort'; - } - _baseUri = Uri.http(url, webAssetServer.basePath); - if (tlsCertPath != null && tlsCertKeyPath != null) { - _baseUri = Uri.https(url, webAssetServer.basePath); - } - return _baseUri!; + return baseUri!; } @override @@ -1090,7 +1097,7 @@ class WebDevFS implements DevFS { : generateMainModule( entrypoint: entrypoint, nativeNullAssertions: nativeNullAssertions, - loaderRootDirectory: _baseUri.toString(), + loaderRootDirectory: baseUri.toString(), ), ); // TODO(zanderso): refactor the asset code in this and the regular devfs to diff --git a/packages/flutter_tools/lib/src/web/bootstrap.dart b/packages/flutter_tools/lib/src/web/bootstrap.dart index f05578b448..dfef115f4f 100644 --- a/packages/flutter_tools/lib/src/web/bootstrap.dart +++ b/packages/flutter_tools/lib/src/web/bootstrap.dart @@ -253,14 +253,6 @@ $_simpleLoaderScript // reloaded into the page. This is then read when a hot restart is triggered // in DDC via the `\$dartReloadModifiedModules` callback. let restartScripts = _currentDirectory + 'restart_scripts.json'; - // Flutter tools should write a file containing the scripts and libraries - // that need to be hot reloaded. This is read in DWDS when a hot reload is - // triggered. - // TODO(srujzs): Ideally, this should be passed to the - // `FrontendServerDdcLibraryBundleStrategyProvider` instead. See - // https://github.com/dart-lang/webdev/issues/2584 for more details. - let reloadScripts = _currentDirectory + 'reload_scripts.json'; - window.\$reloadScriptsPath = reloadScripts; if (!window.\$dartReloadModifiedModules) { window.\$dartReloadModifiedModules = (function(appName, callback) { diff --git a/packages/flutter_tools/pubspec.yaml b/packages/flutter_tools/pubspec.yaml index ec243584e9..b19d9678bf 100644 --- a/packages/flutter_tools/pubspec.yaml +++ b/packages/flutter_tools/pubspec.yaml @@ -13,7 +13,7 @@ dependencies: archive: 3.6.1 args: 2.6.0 dds: 5.0.0 - dwds: 24.3.5 + dwds: 24.3.6 code_builder: 4.10.1 completion: 1.0.1 coverage: 1.11.1 @@ -122,4 +122,4 @@ dartdoc: # Exclude this package from the hosted API docs. nodoc: true -# PUBSPEC CHECKSUM: 466a +# PUBSPEC CHECKSUM: 636b