Description
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:
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 themain()
inweb/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.