The webdev daemon does not properly handle app reconnections. For each page refresh a new app connection is setup while the existing ones are still active. This causes duplicate app connections which quickly pile up after a few refreshes.
The code that causes this:
|
await for (final appConnection in dwds.connectedApps) { |
dwds.connectedApps will emit a new appConnection whenever the browser refreshes, even if this app was already handled in webdev. The app will have the same id as an already active app in _appStates[appId], but this is never checked. Therefore all event handlers will be duplicated.
This can be observed simply by printing some logs on the client and refreshing the page:
Steps to reproduce:
dart create bugtest -t web
cd bugtest
webdev daemon (Or launch a dart web debug session from vscode, which uses the daemon)
- Add
print("Hello Web"); inside the main() in web/main.dart
- Go to chrome (should open automatically) and refresh the page multiple times.
Expected:
After each refresh ONE log event is printed to the terminal, e.g.
[{"event":"app.log","params":{"appId":"CxpfkG6Rz+5OTXWmy8kREA==","log":"Hello Web\n"}}]
Actual:
After each refresh DUPLICATE log events are printed in the number of past refreshes. E.g. after the 10th refresh, 10 duplicate log events are printed.
The webdev daemon does not properly handle app reconnections. For each page refresh a new app connection is setup while the existing ones are still active. This causes duplicate app connections which quickly pile up after a few refreshes.
The code that causes this:
webdev/webdev/lib/src/daemon/app_domain.dart
Line 67 in 697f2f7
dwds.connectedAppswill emit a newappConnectionwhenever the browser refreshes, even if this app was already handled in webdev. The app will have the same id as an already active app in_appStates[appId], but this is never checked. Therefore all event handlers will be duplicated.This can be observed simply by printing some logs on the client and refreshing the page:
Steps to reproduce:
dart create bugtest -t webcd bugtestwebdev daemon(Or launch a dart web debug session from vscode, which uses the daemon)print("Hello Web");inside themain()inweb/main.dartExpected:
After each refresh ONE log event is printed to the terminal, e.g.
[{"event":"app.log","params":{"appId":"CxpfkG6Rz+5OTXWmy8kREA==","log":"Hello Web\n"}}]Actual:
After each refresh DUPLICATE log events are printed in the number of past refreshes. E.g. after the 10th refresh, 10 duplicate log events are printed.