Description
Hot restart is not working properly if the flutter app is paused when the hot restart is initiated.
Repro steps:
- Open flutter
hello_world
project in VSCode - Add a breakpoint on the line that calls
runMain
- Hot restart
Observe the breakpoint not hitting.
Notes
To perform the hot restart we need the app to be running, so we remove all the breakpoints, resume the app, then hot restart, and re-establish breakpoints after the main is reloaded. This seems to be too late for the breakpoints to hit.
Suggestion
Break hot restart into two steps - running the bootstrap and running main (flutter engine main in that case). Then re-establishing the breakpoints can be done in between the two.
Some issues we are encountering currently with this suggestion
-
Race condition between the engine initialization and hot restart. The previous isolate's engine initialization sometimes is delayed and executes in the middle of hot restart, so the engine cleanup is not performed correctly.
-
Hello world app is using an old bootstrap strategy: https://github.com/flutter/flutter/blob/57c7aa53c178f722aec19a76a60552e78ad09997/examples/hello_world/web/index.html#L5
-
After replacing it with a new one,
<html>
<head>
<head>
<title>Hello, World</title>
</head>
<script src="flutter.js" defer></script>
</head>
<body>
<script>
window.addEventListener('load', function (ev) {
// Download main.dart.js
_flutter.loader.loadEntrypoint({
onEntrypointLoaded: async function(engineInitializer) {
// Immediately run the app
await engineInitializer.autoStart();
}
});
});
</script>
</body>
</html>
I am hitting the following: flutter/flutter#121905. Currently blocked on this, will continue the investigation after it is fixed.