Skip to content

Commit 0edf3d8

Browse files
committed
fixed canReuseConnection logic
1 parent b4d5cb1 commit 0edf3d8

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

dwds/lib/src/handlers/dev_handler.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,9 +694,19 @@ class DevHandler {
694694
readyToRunMainCompleter.future,
695695
);
696696

697-
// WebSocket mode: Allow connection reuse for page refreshes and same instance reconnections
697+
// Allow connection reuse for page refreshes and same instance reconnections
698+
final isSameInstance =
699+
existingConnection?.request.instanceId == message.instanceId;
700+
final isKeepAliveReconnect =
701+
existingConnection?.isInKeepAlivePeriod == true;
702+
final hasNoActiveConnection = services?.connectedInstanceId == null;
703+
final noExistingConnection = existingConnection == null;
704+
698705
final canReuseConnection =
699-
services != null && services.connectedInstanceId == null;
706+
services != null &&
707+
(isSameInstance ||
708+
(isKeepAliveReconnect && hasNoActiveConnection) ||
709+
(noExistingConnection && hasNoActiveConnection));
700710

701711
if (canReuseConnection) {
702712
// Reconnect to existing service.

dwds/lib/src/services/web_socket_proxy_service.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,6 @@ class WebSocketProxyService implements VmServiceInterface {
153153
// Update app connection if override provided
154154
appConnection = appConnectionOverride ?? appConnection;
155155

156-
// Clean up existing isolate
157-
if (_isIsolateRunning) {
158-
destroyIsolate();
159-
await Future.delayed(Duration(milliseconds: 10));
160-
}
161-
162156
// Auto-cleanup on connection close
163157
await _appConnectionDoneSubscription?.cancel();
164158
_appConnectionDoneSubscription = appConnection.onDone.asStream().listen((

0 commit comments

Comments
 (0)