dart-lang / webdev

A CLI for Dart web development.
https://pub.dev/packages/webdev
212 stars 75 forks source link

Messages lost when printed shortly after a hot restarting a web app #2361

Open nshahan opened 8 months ago

nshahan commented 8 months ago
import 'dart:async';

main() async {
  for (var i = 0; i < 10; i++) {
    print('Tick: $i');
    await Future.delayed(Duration(seconds: 1));
  }
}

If you run this app and wait for the ticks to print you will see "Tick: 0" to "Tick: 9" printed in the chrome developer console. If you ran the app with vscode and look in the Debug Console you will see the same prints there as well.

Then if you restart the app you will see all ticks "Tick: 0" to "Tick: 9" printed in the chrome developer console but some of the first prints don't make it through to the vscode Debug Console. In my screenshot you can see after the hot restart "Tick: 0" is missing.

Screenshot 2024-01-25 at 12 43 19 PM

This is a problem in Flutter web as well. I spent a while trying to debug a hot restart test because it was relying on this communication and since the first print didn't come through the test thought the hot restart didn't work.

It turns out this is a known issue and if you really need the message to be delivered the workaround is to print it many times https://github.com/flutter/flutter/issues/86202.