Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support hot-reload / hot-restart using vm service protocol #2708

Closed
fuzzybinary opened this issue Aug 6, 2020 · 10 comments
Closed

Support hot-reload / hot-restart using vm service protocol #2708

fuzzybinary opened this issue Aug 6, 2020 · 10 comments
Labels
in cli Relates to running Dart CLI scripts is enhancement
Milestone

Comments

@fuzzybinary
Copy link

The Dart VM Service protocol now supports hot reload and hot restart, meaning Dart command line apps should support proper code hot reloading. It would be nice if Dart-Code utilized this method instead of relying on the flutter tool.

@DanTup DanTup added this to the On Deck milestone Aug 12, 2020
@DanTup DanTup added in cli Relates to running Dart CLI scripts is enhancement labels Aug 12, 2020
DanTup added a commit that referenced this issue Sep 27, 2021
@DanTup DanTup closed this as completed in 09f524e Sep 27, 2021
@DanTup DanTup modified the milestones: On Deck, v3.27.0 Sep 27, 2021
@DanTup
Copy link
Member

DanTup commented Sep 27, 2021

@bkonyi should there be something like a reloadSources service/extension registered when running a Dart script? I can see the VM Service has a reloadServices method, but in Flutter we use the presence of reloadSources and hotRestart services to know when these are available. Should there be similar for Dart, or should we assume it's always available for a recent SDK?

(Also, the original issue here mentions Restart too - but I don't see anything in the docs about that - is it also available through the Dart VM without Flutter?)

@DanTup DanTup reopened this Sep 27, 2021
@DanTup DanTup modified the milestones: v3.27.0, v3.28.0 Sep 29, 2021
@fuzzybinary
Copy link
Author

I may have been mistaken about the ability to do Hot Restart without Flutter.

@DanTup
Copy link
Member

DanTup commented Sep 29, 2021

Ah, got it.

It would be good to support Hot Reload still - but it'd be nice to do it consistently with Flutter (eg. we use the presence of some VM Service to know it's available, and call it via that service) so the extension doesn't need to have logic about when it may/may not be available.

@bkonyi
Copy link

bkonyi commented Sep 29, 2021

Correct, the service protocol doesn't actually implement Hot Restart. That's solely a Flutter extension of the protocol. The VM service protocol does support reloadSources, which is the RPC to trigger a hot reload.

@DanTup
Copy link
Member

DanTup commented Sep 29, 2021

Ah, sounds like there does need to be two paths:

  • Dart: assume Hot Reload is always available, call reloadSources
  • Flutter: use the presence of the reloadSources Service to decide if it's available, and call that instead of reloadSources directly (I presume Flutter is doing something more than just calling the VM service)

The second is all already there, the first would just be adding a new Dart: Hot Reload command that is visible only when running a non-Flutter app, that just calls reloadSources.

@DanTup DanTup closed this as completed in d8c5f6f Oct 26, 2021
@DanTup
Copy link
Member

DanTup commented Oct 26, 2021

There's now an additional command Dart: Hot Reload which will call reloadSources for each isolate when debugging non-Flutter apps:

Oct-26-2021 14-47-46

Actually, Flutter: Hot Reload and Dart: Hot Reload call the same thing (so using either will have the same effect), it's the debug adapter that actually controls which code is run. For Flutter, we need to go through Flutter because otherwise I think some code to rebuild the widget tree could be skipped.

@fuzzybinary
Copy link
Author

Does this work with reload on save or do you have to manually trigger the reload?

@DanTup
Copy link
Member

DanTup commented Oct 26, 2021

@fuzzybinary right now you have to run the command. I'm not sure I'd want to enable it by default, although perhaps we could add a dart.hotReloadOnSave (similar to dart.flutterHotReloadOnSave)? If that would be useful, please file an issue and I'll have a look at getting it into the next release.

(btw there's a beta with the above command available at https://github.com/Dart-Code/Dart-Code/releases/tag/v3.28.0-beta.1 if you want to try it out before the release)

@DanTup
Copy link
Member

DanTup commented Oct 26, 2021

Actually, there's probably some inconsistency here.. If you run a Flutter app and a Dart app at the same time, saving a file probably will reload both, because it will unconditionally send the request to both. So if we were to support both, we should probably improve that too.

@DanTup
Copy link
Member

DanTup commented Oct 27, 2021

Supporting hot-reload-on-save properly turns out to be a bit trickier than I thought and will require some refactoring, so I'm going to leave that until the next release (I've filed #3637). In the meantime, I'm going to ensure the Dart reload is not fired by Flutter's reload-on-save, because it could be unreliable (for example it would not debounce if Flutter supports its own internal debounce, which would result in it triggering a lot when you do things like Save All).

DanTup added a commit that referenced this issue Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in cli Relates to running Dart CLI scripts is enhancement
Projects
None yet
Development

No branches or pull requests

3 participants