Skip to content

Commit f5587a4

Browse files
committed
[dwds] callServiceExtension should check all extensions and return kMethodNotFound when extension not found and remove reassemble from reload
dart-lang#2584 Currently, callServiceExtension checks the extensionRpcs field in the VM service. This list is populated when DWDS starts and checks the extensions currently registered in the runtime. This list is prone to becoming stale, however, as services may be registered or removed through the runtime (via dart:developer) later. This is true for ext.flutter.reassemble, where DWDS can not find the service because we computed the list too early. Instead, we should seek to always check the runtime for the current registered extensions and then update this list whenever we do. It’s still prone to becoming stale, but it is less stale. Ideally, we would override extensionRpcs and fetch the current registered extensions, but that isn’t possible since it requires awaiting a future. We also can’t ignore this field altogether because it looks like clients, like Dart DevTools, uses this field. callServiceExtension should also return kMethodNotFound instead of its current JS evaluation error when an extension is not present. Lastly, the reassemble call is removed from reload as it can now be safely called in Flutter tools instead.
1 parent 8f146a1 commit f5587a4

File tree

5 files changed

+23
-48
lines changed

5 files changed

+23
-48
lines changed

dwds/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
## 24.3.7-wip
22

3+
- `callServiceExtension` now checks the runtime for the list of registered
4+
service extensions. It also now throws a `RPCError` with
5+
`RPCErrorKind.kMethodNotFound` when a service extension is not found instead
6+
of throwing a JS evaluation error.
7+
- The registered extension `reassemble` is now no longer called when calling
8+
`reloadSources`. Users should call `reassemble` using `callServiceExtension`.
9+
310
## 24.3.6
411

512
- Bump minimum sdk version to 3.7.0

dwds/lib/src/debugging/inspector.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ class AppInspector implements AppInspectorInterface {
115115
await DartUri.initialize();
116116
DartUri.recordAbsoluteUris(libraries.map((lib) => lib.uri).nonNulls);
117117
DartUri.recordAbsoluteUris(scripts.map((script) => script.uri).nonNulls);
118-
119-
isolate.extensionRPCs?.addAll(await _getExtensionRpcs());
120118
}
121119

122120
static IsolateRef _toIsolateRef(Isolate isolate) => IsolateRef(
@@ -760,11 +758,16 @@ class AppInspector implements AppInspectorInterface {
760758
scriptId == null ? null : _scriptRefsById[scriptId];
761759

762760
/// Runs an eval on the page to compute all existing registered extensions.
763-
Future<List<String>> _getExtensionRpcs() async {
761+
///
762+
/// Combines this with the RPCs registered in the [isolate]. Use this over
763+
/// [Isolate.extensionRPCs] as this computes a live set.
764+
///
765+
/// Updates [Isolate.extensionRPCs] to this set.
766+
Future<Set<String>> getExtensionRpcs() async {
764767
final expression =
765768
globalToolConfiguration.loadStrategy.dartRuntimeDebugger
766769
.getDartDeveloperExtensionNamesJsExpression();
767-
final extensionRpcs = <String>[];
770+
final extensionRpcs = <String>{};
768771
final params = {
769772
'expression': expression,
770773
'returnByValue': true,
@@ -784,6 +787,7 @@ class AppInspector implements AppInspectorInterface {
784787
s,
785788
);
786789
}
790+
isolate.extensionRPCs = List<String>.from(extensionRpcs);
787791
return extensionRpcs;
788792
}
789793

dwds/lib/src/injected/client.js

Lines changed: 0 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dwds/lib/src/services/chrome_proxy_service.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ class ChromeProxyService implements VmServiceInterface {
343343
// TODO: We shouldn't need to fire these events since they exist on the
344344
// isolate, but devtools doesn't recognize extensions after a page refresh
345345
// otherwise.
346-
for (final extensionRpc in inspector.isolate.extensionRPCs ?? []) {
346+
for (final extensionRpc in await inspector.getExtensionRpcs()) {
347347
_streamNotify(
348348
'Isolate',
349349
Event(
@@ -509,6 +509,13 @@ class ChromeProxyService implements VmServiceInterface {
509509
v is String ? v : jsonEncode(v),
510510
),
511511
);
512+
if ((await inspector.getExtensionRpcs()).contains(method) != true) {
513+
throw RPCError(
514+
method,
515+
RPCErrorKind.kMethodNotFound.code,
516+
'Unknown service method: $method',
517+
);
518+
}
512519
final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
513520
.invokeExtensionJsExpression(method, jsonEncode(stringArgs));
514521
final result = await inspector.jsEvaluate(expression, awaitPromise: true);

dwds/web/reloader/ddc_library_bundle_restarter.dart

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ extension type _Debugger._(JSObject _) implements JSObject {
3030
await invokeExtension(method, '{}').toDart;
3131
}
3232
}
33-
34-
Future<void> maybeInvokeFlutterReassemble() async {
35-
final method = 'ext.flutter.reassemble';
36-
if (extensionNames.toDart.contains(method.toJS)) {
37-
await invokeExtension(method, '{}').toDart;
38-
}
39-
}
4033
}
4134

4235
@JS('XMLHttpRequest')
@@ -92,9 +85,5 @@ class DdcLibraryBundleRestarter implements Restarter {
9285
}
9386
}
9487
await _dartDevEmbedder.hotReload(filesToLoad, librariesToReload).toDart;
95-
// TODO(srujzs): Reassembling is slow. It's roughly almost the time it takes
96-
// to recompile and do a hot reload. We should do some better profiling and
97-
// see if we can improve this.
98-
await _dartDevEmbedder.debugger.maybeInvokeFlutterReassemble();
9988
}
10089
}

0 commit comments

Comments
 (0)