Skip to content

Commit ecde807

Browse files
authored
fix no-op hot restarts (#311)
Fixes #302 Previously the behavior was pretty broken, after talking with @jacob314 we decided the best thing to do is actually restart the app (even if it doesn't have anything new to load). I also did some other cleanup to make things more robust: - Handle errors from the $dartHotRestart call and forward them along - Return a promise to JS from the `$dartHotRestart` call so that it can be properly awaited (we weren't actually waiting before because it was a dart future, so this may have contributed to race conditions). - Return an actual boolean result (success/failure) for the `$dartHotRestart` call.
1 parent a298f98 commit ecde807

File tree

5 files changed

+4530
-4463
lines changed

5 files changed

+4530
-4463
lines changed

webdev/lib/src/serve/debugger/webdev_vm_client.dart

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,24 @@ class WebdevVmClient {
3737
.add(jsonDecode(request) as Map<String, dynamic>));
3838
client.registerServiceCallback('hotRestart', (request) async {
3939
debugService.chromeProxyService.destroyIsolate();
40-
await debugService.chromeProxyService.tabConnection.runtime.sendCommand(
41-
'Runtime.evaluate',
42-
params: {'expression': r'$dartHotRestart();', 'awaitPromise': true});
43-
unawaited(debugService.chromeProxyService.createIsolate());
44-
return {'result': Success().toJson()};
40+
var response = await debugService.chromeProxyService.tabConnection.runtime
41+
.sendCommand('Runtime.evaluate', params: {
42+
'expression': r'$dartHotRestart();',
43+
'awaitPromise': true
44+
});
45+
var exceptionDetails = response.result['exceptionDetails'];
46+
if (exceptionDetails != null) {
47+
return {
48+
'error': {
49+
'code': -32603,
50+
'message': exceptionDetails['exception']['description'],
51+
'data': exceptionDetails,
52+
}
53+
};
54+
} else {
55+
unawaited(debugService.chromeProxyService.createIsolate());
56+
return {'result': Success().toJson()};
57+
}
4558
});
4659
await client.registerService('hotRestart', 'WebDev');
4760

0 commit comments

Comments
 (0)