Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dwds/lib/src/utilities/sdk_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class SdkConfiguration {
class DefaultSdkConfigurationProvider extends SdkConfigurationProvider {
DefaultSdkConfigurationProvider();

late SdkConfiguration _configuration = _create();
late final SdkConfiguration _configuration = _create();

/// Create and validate configuration matching the default SDK layout.
@override
Expand Down
8 changes: 3 additions & 5 deletions dwds/web/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

@JS()
library hot_reload_client;

Expand Down Expand Up @@ -38,7 +36,7 @@ const _batchDelayMilliseconds = 1000;

// GENERATE:
// pub run build_runner build web
Future<void> main() {
Future<void>? main() {
return runZonedGuarded(() async {
// Set the unique id for this instance of the app.
// Test apps may already have this set.
Expand Down Expand Up @@ -221,13 +219,13 @@ String _fixProtocol(String url) {
external String get dartAppId;

@JS(r'$dartAppInstanceId')
external String get dartAppInstanceId;
external String? get dartAppInstanceId;

@JS(r'$dwdsDevHandlerPath')
external String get dwdsDevHandlerPath;

@JS(r'$dartAppInstanceId')
external set dartAppInstanceId(String id);
external set dartAppInstanceId(String? id);

@JS(r'$dartModuleStrategy')
external String get dartModuleStrategy;
Expand Down
4 changes: 1 addition & 3 deletions dwds/web/promise.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

@JS()
library webdev.web.promise;

Expand Down Expand Up @@ -49,7 +47,7 @@ Future<T> toFuture<T>(Promise<T> promise) {
final completer = Completer<T>();
promise.then(
allowInterop(completer.complete),
allowInterop(completer.completeError),
allowInterop((e) => completer.completeError(e)),
);
return completer.future;
}
13 changes: 6 additions & 7 deletions dwds/web/reloader/legacy_restarter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

import 'dart:async';
import 'dart:html';
import 'dart:js';
Expand All @@ -12,7 +10,7 @@ import 'restarter.dart';

class LegacyRestarter implements Restarter {
@override
Future<bool> restart({String runId}) async {
Future<bool> restart({String? runId}) async {
final dartLibrary = context['dart_library'] as JsObject;
if (runId == null) {
dartLibrary.callMethod('reload');
Expand All @@ -22,16 +20,17 @@ class LegacyRestarter implements Restarter {
]);
}
final reloadCompleter = Completer<bool>();
StreamSubscription sub;
sub = window.onMessage.listen((event) {
final sub = window.onMessage.listen((event) {
final message = event.data;
if (message is Map &&
message['type'] == 'DDC_STATE_CHANGE' &&
message['state'] == 'restart_end') {
reloadCompleter.complete(true);
sub.cancel();
}
});
return reloadCompleter.future;
return reloadCompleter.future.then((value) {
sub.cancel();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this moved into the then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the sub is not defined inside the callback to window.onMessage.listen yet (at least analyzer does not think so:) - so i moved it to where it logically behaves the same but cancels the sub as before.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. Hmm, could the subscription be late (so we would follow the pattern as before)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it does not help unfortunately. I know this pattern is given as an example in many places but the analyzer is rejecting it currently (and I tend to agree with it, even just for safety, don't want the wrong pointer to be pinned here:)

return value;
});
}
}
4 changes: 1 addition & 3 deletions dwds/web/reloader/manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

import 'dart:async';
import 'dart:convert';
import 'dart:html';
Expand All @@ -28,7 +26,7 @@ class ReloadingManager {
/// - called hotRestart with the same runId
///
/// The apps are restarted at the same time on the first call.
Future<bool> hotRestart({String runId}) async {
Future<bool> hotRestart({String? runId}) async {
_beforeRestart();
final result = await _restarter.restart(runId: runId);
_afterRestart(result);
Expand Down
23 changes: 11 additions & 12 deletions dwds/web/reloader/require_restarter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

@JS()
library require_reloading_manager;

Expand All @@ -23,7 +21,8 @@ import 'restarter.dart';
/// The last known digests of all the modules in the application.
///
/// This is updated in place during calls to hotRestart.
Map<String, String> _lastKnownDigests;
/// TODO(annagrin): can this be a private field in RequireRestarter?
late Map<String, String> _lastKnownDigests;

@JS(r'$requireLoader')
external RequireLoader get requireLoader;
Expand Down Expand Up @@ -90,8 +89,8 @@ abstract class JsMap<K, V> {
/// Handles hot restart reloading for use with the require module system.
class RequireRestarter implements Restarter {
final _moduleOrdering = HashMap<String, int>();
SplayTreeSet<String> _dirtyModules;
var _running = Completer<bool>()..complete();
late SplayTreeSet<String> _dirtyModules;
var _running = Completer<bool>()..complete(true);

var count = 0;

Expand All @@ -100,7 +99,7 @@ class RequireRestarter implements Restarter {
}

@override
Future<bool> restart({String runId}) async {
Future<bool> restart({String? runId}) async {
final developer = getProperty(require('dart_sdk'), 'developer');
if (callMethod(getProperty(developer, '_extensions'), 'containsKey',
['ext.flutter.disassemble']) as bool) {
Expand All @@ -117,7 +116,7 @@ class RequireRestarter implements Restarter {
'Unable to find an existing digest for module: $moduleId.');
_reloadPage();
} else if (_lastKnownDigests[moduleId] != newDigests[moduleId]) {
_lastKnownDigests[moduleId] = newDigests[moduleId];
_lastKnownDigests[moduleId] = newDigests[moduleId]!;
modulesToLoad.add(moduleId);
}
}
Expand Down Expand Up @@ -145,7 +144,7 @@ class RequireRestarter implements Restarter {
}

List<String> _moduleParents(String module) =>
requireLoader.moduleParentsGraph.get(module)?.cast() ?? [];
requireLoader.moduleParentsGraph.get(module).cast();

int _moduleTopologicalCompare(String module1, String module2) {
var topological = 0;
Expand All @@ -159,8 +158,8 @@ class RequireRestarter implements Restarter {
'Unable to fetch ordering info for module: $missing');
}

topological =
Comparable.compare(_moduleOrdering[module2], _moduleOrdering[module1]);
topological = Comparable.compare(
_moduleOrdering[module2]!, _moduleOrdering[module1]!);

if (topological == 0) {
// If modules are in cycle (same strongly connected component) compare
Expand All @@ -183,13 +182,13 @@ class RequireRestarter implements Restarter {
var reloadedModules = 0;
try {
_dirtyModules.addAll(modules);
String previousModuleId;
String? previousModuleId;
while (_dirtyModules.isNotEmpty) {
final moduleId = _dirtyModules.first;
_dirtyModules.remove(moduleId);
final parentIds = _moduleParents(moduleId);
// Check if this is the root / bootstrap module.
if (parentIds == null || parentIds.isEmpty) {
if (parentIds.isEmpty) {
// The bootstrap module is not reloaded but we need to update the
// $dartRunMain reference to the newly loaded child module.
final childModule = callMethod(
Expand Down
4 changes: 1 addition & 3 deletions dwds/web/reloader/restarter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

abstract class Restarter {
/// Attemps to perform a hot restart and returns whether it was successful or
/// not.
Future<bool> restart({String runId});
Future<bool> restart({String? runId});
}
9 changes: 6 additions & 3 deletions dwds/web/run_main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @dart = 2.9
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:html';

/// Creates a script that will run properly when strict CSP is enforced.
Expand All @@ -15,7 +18,7 @@ final ScriptElement Function() _createScript = (() {
final _noncePattern = RegExp('^[\\w+/_-]+[=]{0,2}\$');

/// Returns CSP nonce, if set for any script tag.
String _findNonce() {
String? _findNonce() {
final elements = window.document.querySelectorAll('script');
for (final element in elements) {
final nonceValue =
Expand All @@ -33,6 +36,6 @@ String _findNonce() {
/// handling zone.
void runMain() {
final scriptElement = _createScript()..innerHtml = r'window.$dartRunMain();';
document.body.append(scriptElement);
document.body!.append(scriptElement);
Future.microtask(scriptElement.remove);
}