Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- Fix pausing starting of `main` after the hot restart.
- Updating bootstrapper for DDC library bundler module format + Frontend Server.
- Fix setting up breakpoints when handling in-app restarts with attached debugger.
- Fix setting up breakpoints when handling full reloads from attached
debugger / page refreshes.

## 26.2.2

Expand Down
56 changes: 28 additions & 28 deletions dwds/lib/src/handlers/dev_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -636,21 +636,11 @@ class DevHandler {
readyToRunMainCompleter.future,
);

// We can take over a connection if there is no connectedInstanceId (this
// means the client completely disconnected), or if the existing
// AppConnection is in the KeepAlive state (this means it disconnected but
// is still waiting for a possible reconnect - this happens during a page
// reload).
final canReconnect =
services != null &&
(services.connectedInstanceId == null ||
existingConnection?.isInKeepAlivePeriod == true);

if (canReconnect) {
if (_canReconnect(existingConnection, message)) {
// Disconnect any old connection (eg. those in the keep-alive waiting
// state when reloading the page).
existingConnection?.shutDown();
final chromeProxy = services.proxyService;
final chromeProxy = services!.proxyService;
if (chromeProxy is ChromeProxyService) {
chromeProxy.destroyIsolate();
}
Expand Down Expand Up @@ -703,24 +693,10 @@ class DevHandler {
readyToRunMainCompleter.future,
);

// Allow connection reuse for page refreshes and same instance reconnections
final isSameInstance =
existingConnection?.request.instanceId == message.instanceId;
final isKeepAliveReconnect =
existingConnection?.isInKeepAlivePeriod == true;
final hasNoActiveConnection = services?.connectedInstanceId == null;
final noExistingConnection = existingConnection == null;

final canReconnect =
services != null &&
(isSameInstance ||
(isKeepAliveReconnect && hasNoActiveConnection) ||
(noExistingConnection && hasNoActiveConnection));

if (canReconnect) {
if (_canReconnect(existingConnection, message)) {
// Reconnect to existing service.
await _reconnectToService(
services,
services!,
existingConnection,
connection,
message,
Expand Down Expand Up @@ -749,6 +725,30 @@ class DevHandler {
return connection;
}

/// Allow connection reuse for page refreshes and same instance reconnections
bool _canReconnect(
AppConnection? existingConnection,
ConnectRequest message,
) {
final services = _servicesByAppId[message.appId];

if (services == null) {
return false;
}

if (existingConnection?.request.instanceId == message.instanceId) {
return true;
}

final isKeepAliveReconnect =
existingConnection?.isInKeepAlivePeriod == true;
final hasNoActiveConnection = services.connectedInstanceId == null;
final noExistingConnection = existingConnection == null;

return (isKeepAliveReconnect && hasNoActiveConnection) ||
(noExistingConnection && hasNoActiveConnection);
}

/// Handles reconnection to existing services for web-socket mode.
Future<void> _reconnectToService(
AppDebugServices services,
Expand Down
16 changes: 13 additions & 3 deletions dwds/lib/src/injected/client.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion dwds/web/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,22 @@ Future<void>? main() {
() async {
// Set the unique id for this instance of the app.
// Test apps may already have this set.
dartAppInstanceId ??= const Uuid().v1();
const dartAppInstanceIdKey = 'dartAppInstanceId';
if (dartAppInstanceId == null) {
// Check the session storage for the instance id.
final storedInstanceId = window.sessionStorage.getItem(
dartAppInstanceIdKey,
);
if (storedInstanceId != null) {
dartAppInstanceId = storedInstanceId;
} else {
dartAppInstanceId = const Uuid().v1();
window.sessionStorage.setItem(
dartAppInstanceIdKey,
dartAppInstanceId!,
);
}
}

final fixedPath = _fixProtocol(dwdsDevHandlerPath);
final fixedUri = Uri.parse(fixedPath);
Expand Down