Skip to content

Commit e43744b

Browse files
authored
[dwds] Fix ping event serialization by introducing PingRequest (#2821)
**Changes:** - Replaced the raw map `{'type': 'ping'}` used for client connection checks with a proper `PingRequest` class. This fixes a `TypeError` in the browser client when trying to deserialize the raw map as a list (due to expected wire format mismatch), and aligns the ping event with the ongoing migration to standard JSON serialization in DWDS. **Tests:** - Added unit tests to verify the change. Related to #2806
1 parent 1063eb0 commit e43744b

9 files changed

Lines changed: 210 additions & 180 deletions

File tree

dwds/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 27.1.1-wip
2+
3+
- Replace raw map for client ping checks with a proper `PingRequest` class and update client deserialization handling.
4+
15
## 27.1.0
26

37
- Add `appName` to `DartDevelopmentServiceConfiguration`.

dwds/lib/data/ping_request.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// A ping request to check client connection.
6+
class PingRequest {
7+
PingRequest();
8+
9+
Map<String, dynamic> toJson() => {};
10+
11+
factory PingRequest.fromJson(Map<String, dynamic> json) {
12+
return PingRequest();
13+
}
14+
15+
@override
16+
bool operator ==(Object other) =>
17+
identical(this, other) || other is PingRequest;
18+
19+
@override
20+
int get hashCode => 0;
21+
22+
@override
23+
String toString() => 'PingRequest';
24+
}

dwds/lib/src/handlers/dev_handler.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import 'package:dwds/data/hot_reload_response.dart';
1818
import 'package:dwds/data/hot_restart_request.dart';
1919
import 'package:dwds/data/hot_restart_response.dart';
2020
import 'package:dwds/data/isolate_events.dart';
21+
import 'package:dwds/data/ping_request.dart';
2122
import 'package:dwds/data/register_event.dart';
2223
import 'package:dwds/data/run_request.dart';
2324
import 'package:dwds/data/service_extension_request.dart';
@@ -165,7 +166,8 @@ class DevHandler {
165166
IsolateExit() => ['IsolateExit', request.toJson()],
166167
ErrorResponse() => ['ErrorResponse', request.toJson()],
167168
RegisterEvent() => ['RegisterEvent', request.toJson()],
168-
Map() => request, // Already a raw message (e.g., ping)
169+
PingRequest() => ['PingRequest', request.toJson()],
170+
Map() => request,
169171
_ => throw UnsupportedError('Unknown request type: $request'),
170172
};
171173
}

0 commit comments

Comments
 (0)