-
Notifications
You must be signed in to change notification settings - Fork 195
Open
Description
Hi,
I'm using your Dart Socket.IO client (v3.1.2) in a Flutter Web application alongside a Socket.IO server. Whenever the server restarts, the client throws the following exception, which breaks the reconnection logic:
TypeError: Instance of 'JSArray<dynamic>': type 'List<dynamic>' is not a subtype of type 'List<String>'
The issue seems to stem from this line in engine/socket.dart :
transports = opts['transports'] ?? ['polling', 'websocket', 'webtransport'];
On Flutter Web, opts['transports']
becomes a JSArray<dynamic>
, which gets converted into a List<dynamic>
instead of the expected List<String>
. This causes the type mismatch.
A potential fix could be to cast the list explicitly like this:
transports = (opts['transports'] as List<dynamic>?)?.cast<String>() ?? ['polling', 'websocket', 'webtransport'];
The logs look like this:
FINE: 2025-06-16 10:13:36.587: socket_io_client:engine.Socket: socket close with reason: "transport close"
FINE: 2025-06-16 10:13:36.587: socket_io_client:Manager: closed due to transport close
FINE: 2025-06-16 10:13:36.588: socket_io_client:Manager: cleanup
FINE: 2025-06-16 10:13:36.588: socket_io_client:Manager: will wait %dms before reconnect attempt
FINE: 2025-06-16 10:13:37.163: socket_io_client:Manager: attempting reconnect
FINE: 2025-06-16 10:13:37.164: socket_io_client:Manager: readyState closed
FINE: 2025-06-16 10:13:37.164: socket_io_client:Manager: opening http://localhost:6095
DartError: TypeError: Instance of 'JSArray<dynamic>': type 'List<dynamic>' is not a subtype of type 'List<String>'
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 307:3 throw_
dart-sdk/lib/_internal/js_dev_runtime/private/profile.dart 117:39 _failedAsCheck
dart-sdk/lib/_internal/js_shared/lib/rti.dart 1554:3 _generalAsCheckImplementation
packages/socket_io_client/src/engine/socket.dart 82:5 new
packages/socket_io_client/src/manager.dart 173:28 open
packages/socket_io_client/src/manager.dart 434:9 <fn>
dart-sdk/lib/_internal/js_dev_runtime/private/isolate_helper.dart 47:11 internalCallback
BR
andynvt, jhonatan-3a and kherel
Metadata
Metadata
Assignees
Labels
No labels