Skip to content

Commit fa04787

Browse files
jyameomboetger
authored andcommitted
remove --start-paused flag by default and set useDwdsWebSocketConnect… (flutter#170612)
- Removed --start-paused flag by default and set useDwdsWebSocketConnection in DWDS - Updated logic for adding middleware and generating loadindicator - Revert changes in flutter#170610 Related to dart-lang/webdev#2605. Fixes dart-lang/sdk#60289. Sibling PR in DWDS: dart-lang/webdev#2629 This PR will need to be submitted before this one. The pubspec must be updated with a new release of DWDS after the changes are submitted
1 parent bf28060 commit fa04787

File tree

6 files changed

+41
-60
lines changed

6 files changed

+41
-60
lines changed

packages/flutter_tools/lib/executable.dart

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,6 @@ Future<void> main(List<String> args) async {
9999
userMessages: UserMessages(),
100100
);
101101

102-
// Silently add --start-paused if running with -d web-server and --web-experimental-hot-reload,
103-
// and --start-paused is not already present. This is to support hot reload in web-server environment.
104-
// TODO(yjessy): Remove this workaround once https://github.com/dart-lang/sdk/issues/60688 is resolved.
105-
106-
if (args.contains('-d') &&
107-
args.contains('web-server') &&
108-
args.contains('--web-experimental-hot-reload') &&
109-
!args.contains('--start-paused')) {
110-
args = List<String>.from(args)..add('--start-paused');
111-
}
112-
113102
await runner.run(
114103
args,
115104
() => generateCommands(verboseHelp: verboseHelp, verbose: verbose),

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

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ typedef DwdsLauncher =
4949
required Stream<BuildResult> buildResults,
5050
required ConnectionProvider chromeConnection,
5151
required ToolConfiguration toolConfiguration,
52-
bool injectDebuggingSupportCode,
52+
bool useDwdsWebSocketConnection,
5353
});
5454

5555
// A minimal index for projects that do not yet support web. A meta tag is used
@@ -264,9 +264,11 @@ class WebAssetServer implements AssetReader {
264264
// TODO(markzipan): Make sure this default value aligns with that in the debugger options.
265265
bool ddcModuleSystem = false,
266266
bool canaryFeatures = false,
267+
bool useDwdsWebSocketConnection = false,
267268
required FileSystem fileSystem,
268269
required Logger logger,
269270
required Platform platform,
271+
bool shouldEnableMiddleware = false,
270272
}) async {
271273
// TODO(srujzs): Remove this assertion when the library bundle format is
272274
// supported without canary mode.
@@ -383,15 +385,6 @@ class WebAssetServer implements AssetReader {
383385
logging.Logger.root.level = logging.Level.ALL;
384386
logging.Logger.root.onRecord.listen((logging.LogRecord event) => log(logger, event));
385387

386-
// Retrieve connected web devices.
387-
final List<Device>? devices = await globals.deviceManager?.getAllDevices();
388-
final Set<String> connectedWebDeviceIds =
389-
devices
390-
?.where((Device d) => d.platformType == PlatformType.web && d.isConnected)
391-
.map((Device d) => d.id)
392-
.toSet() ??
393-
<String>{};
394-
395388
// In debug builds, spin up DWDS and the full asset server.
396389
final Dwds dwds = await dwdsLauncher(
397390
assetReader: server,
@@ -442,15 +435,12 @@ class WebAssetServer implements AssetReader {
442435
),
443436
appMetadata: AppMetadata(hostname: hostname),
444437
),
445-
// Inject the debugging support code if connected web devices are present,
446-
// and user specified a device id that matches a connected web device.
447-
// If the user did not specify a device id, we use chrome as the default.
448-
injectDebuggingSupportCode:
449-
connectedWebDeviceIds.isNotEmpty &&
450-
connectedWebDeviceIds.contains(globals.deviceManager?.specifiedDeviceId ?? 'chrome'),
438+
// Use DWDS WebSocket-based connection instead of Chrome-based connection for debugging
439+
useDwdsWebSocketConnection: useDwdsWebSocketConnection,
451440
);
452441
shelf.Pipeline pipeline = const shelf.Pipeline();
453-
if (enableDwds) {
442+
443+
if (shouldEnableMiddleware) {
454444
pipeline = pipeline.addMiddleware(middleware);
455445
pipeline = pipeline.addMiddleware(dwds.middleware);
456446
}
@@ -877,6 +867,7 @@ class WebDevFS implements DevFS {
877867
required this.isWasm,
878868
required this.useLocalCanvasKit,
879869
required this.rootDirectory,
870+
this.useDwdsWebSocketConnection = false,
880871
required this.fileSystem,
881872
required this.logger,
882873
required this.platform,
@@ -912,6 +903,7 @@ class WebDevFS implements DevFS {
912903
final WebRendererMode webRenderer;
913904
final bool isWasm;
914905
final bool useLocalCanvasKit;
906+
final bool useDwdsWebSocketConnection;
915907
final FileSystem fileSystem;
916908
final Logger logger;
917909
final Platform platform;
@@ -920,6 +912,10 @@ class WebDevFS implements DevFS {
920912

921913
Dwds get dwds => webAssetServer.dwds;
922914

915+
/// Whether middleware should be enabled for this web development server.
916+
/// Middleware is enabled when using Chrome device or DDC module system.
917+
bool get shouldEnableMiddleware => chromiumLauncher != null || ddcModuleSystem;
918+
923919
// A flag to indicate whether we have called `setAssetDirectory` on the target device.
924920
@override
925921
bool hasSetAssetDirectory = false;
@@ -1017,9 +1013,11 @@ class WebDevFS implements DevFS {
10171013
testMode: testMode,
10181014
ddcModuleSystem: ddcModuleSystem,
10191015
canaryFeatures: canaryFeatures,
1016+
useDwdsWebSocketConnection: useDwdsWebSocketConnection,
10201017
fileSystem: fileSystem,
10211018
logger: logger,
10221019
platform: platform,
1020+
shouldEnableMiddleware: shouldEnableMiddleware,
10231021
);
10241022
return baseUri!;
10251023
}
@@ -1101,13 +1099,13 @@ class WebDevFS implements DevFS {
11011099
entrypoint: entrypoint,
11021100
ddcModuleLoaderUrl: 'ddc_module_loader.js',
11031101
mapperUrl: 'stack_trace_mapper.js',
1104-
generateLoadingIndicator: enableDwds,
1102+
generateLoadingIndicator: shouldEnableMiddleware,
11051103
isWindows: platform.isWindows,
11061104
)
11071105
: generateBootstrapScript(
11081106
requireUrl: 'require.js',
11091107
mapperUrl: 'stack_trace_mapper.js',
1110-
generateLoadingIndicator: enableDwds,
1108+
generateLoadingIndicator: shouldEnableMiddleware,
11111109
),
11121110
);
11131111
const String onLoadEndBootstrap = 'on_load_end_bootstrap.js';

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,26 @@ Please provide a valid TCP port (an integer between 0 and 65535, inclusive).
303303
? WebExpressionCompiler(device!.generator!, fileSystem: _fileSystem)
304304
: null;
305305

306+
// Retrieve connected web devices, excluding the web server device.
307+
final List<Device>? devices = await globals.deviceManager?.getAllDevices();
308+
final Set<String> nonWebServerConnectedDeviceIds =
309+
devices
310+
?.where(
311+
(Device d) =>
312+
d.platformType == PlatformType.web &&
313+
d.isConnected &&
314+
d.id != WebServerDevice.kWebServerDeviceId,
315+
)
316+
.map((Device d) => d.id)
317+
.toSet() ??
318+
<String>{};
319+
320+
// Use Chrome-based connection only if we have a connected ChromiumDevice
321+
// Otherwise, use DWDS WebSocket connection
322+
final bool useDwdsWebSocketConnection =
323+
!(_chromiumLauncher != null &&
324+
nonWebServerConnectedDeviceIds.contains(device!.device!.id));
325+
306326
device!.devFS = WebDevFS(
307327
hostname: debuggingOptions.hostname ?? 'localhost',
308328
port: await getPort(),
@@ -327,6 +347,7 @@ Please provide a valid TCP port (an integer between 0 and 65535, inclusive).
327347
isWasm: debuggingOptions.webUseWasm,
328348
useLocalCanvasKit: debuggingOptions.buildInfo.useLocalCanvasKit,
329349
rootDirectory: fileSystem.directory(projectRootPath),
350+
useDwdsWebSocketConnection: useDwdsWebSocketConnection,
330351
fileSystem: fileSystem,
331352
logger: logger,
332353
platform: _platform,

packages/flutter_tools/lib/src/runner/flutter_command.dart

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import '../project.dart';
2929
import '../reporting/reporting.dart';
3030
import '../reporting/unified_analytics.dart';
3131
import '../version.dart';
32-
import '../web/web_device.dart';
3332
import 'flutter_command_runner.dart';
3433
import 'target_devices.dart';
3534

@@ -1334,11 +1333,7 @@ abstract class FlutterCommand extends Command<void> {
13341333
// TODO(natebiggs): Delete this when new DDC module system is the default.
13351334
final bool webEnableHotReload =
13361335
argParser.options.containsKey(FlutterOptions.kWebExperimentalHotReload) &&
1337-
boolArg(FlutterOptions.kWebExperimentalHotReload) &&
1338-
// TODO(nshahan): Enable on web-server when the app is started correctly
1339-
// https://github.com/dart-lang/sdk/issues/60289.
1340-
(globals.deviceManager == null ||
1341-
globals.deviceManager!.specifiedDeviceId != WebServerDevice.kWebServerDeviceId);
1336+
boolArg(FlutterOptions.kWebExperimentalHotReload);
13421337

13431338
String? codeSizeDirectory;
13441339
if (argParser.options.containsKey(FlutterOptions.kAnalyzeSize) &&

packages/flutter_tools/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dependencies:
1313
archive: 3.6.1
1414
args: 2.7.0
1515
dds: 5.0.2
16-
dwds: 24.3.10
16+
dwds: 24.3.11
1717
code_builder: 4.10.1
1818
completion: 1.0.1
1919
coverage: 1.14.1
@@ -126,4 +126,4 @@ dev_dependencies:
126126
dartdoc:
127127
# Exclude this package from the hosted API docs.
128128
nodoc: true
129-
# PUBSPEC CHECKSUM: gpkldp
129+
# PUBSPEC CHECKSUM: 8r3ct9

packages/flutter_tools/test/general.shard/runner/flutter_command_test.dart

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -370,28 +370,6 @@ void main() {
370370
},
371371
);
372372

373-
// TODO(nshahan): Delete when hot reload on web is always enabled
374-
// https://github.com/flutter/flutter/issues/170685.
375-
testUsingContext('web hot reload enabled by default', () async {
376-
final DummyFlutterCommand dummyCommand =
377-
DummyFlutterCommand()..usesWebOptions(verboseHelp: false);
378-
final CommandRunner<void> runner = createTestCommandRunner(dummyCommand);
379-
await runner.run(<String>['dummy']);
380-
final BuildInfo buildInfo = await dummyCommand.getBuildInfo(forcedBuildMode: BuildMode.debug);
381-
expect(buildInfo.webEnableHotReload, isTrue);
382-
});
383-
384-
// TODO(nshahan): Delete when hot reload doesn't break on web-server
385-
// https://github.com/dart-lang/sdk/issues/60289.
386-
testUsingContext('web hot reload disabled when device is web-server', () async {
387-
final DummyFlutterCommand dummyCommand =
388-
DummyFlutterCommand()..usesWebOptions(verboseHelp: false);
389-
final CommandRunner<void> runner = createTestCommandRunner(dummyCommand);
390-
await runner.run(<String>['dummy', '-d', 'web-server']);
391-
final BuildInfo buildInfo = await dummyCommand.getBuildInfo(forcedBuildMode: BuildMode.debug);
392-
expect(buildInfo.webEnableHotReload, isFalse);
393-
});
394-
395373
group('signals tests', () {
396374
late FakeIoProcessSignal mockSignal;
397375
late ProcessSignal signalUnderTest;

0 commit comments

Comments
 (0)