Commit bfa480a
fix(realtime): add explicit type cast to fix web hot restart TypeError (#1308)
* fix(realtime): add explicit type cast to fix web hot restart TypeError
Fixes TypeError when using RealtimeChannel.off() on Flutter web during hot restart.
JavaScript interop causes type inference to fail on .where().toList() chains,
returning List<dynamic> instead of List<Binding>, which fails type checks.
Root Cause:
- RealtimeChannel.off() at line 475-478 used .where().toList() without explicit casting
- RealtimeClient.remove() at line 332 had similar pattern
- During web hot restart, JS interop loses type information
- Assignment back to typed collections (Map<String, List<Binding>>, List<RealtimeChannel>) fails
Solution:
- Added .cast<Binding>() to RealtimeChannel.off() after .toList()
- Added .cast<RealtimeChannel>() to RealtimeClient.remove() after .toList()
- Follows existing pattern in realtime_presence.dart (lines 172, 177, 240, 303)
- Consistent with type safety improvements from commit 102595d
Acceptance Criteria:
- [x] The off() method successfully removes event bindings on Flutter web without type errors
- [x] Hot restart on Flutter web no longer throws TypeError
- [x] All existing tests pass (98 tests)
- [x] No breaking changes to public API
- [x] Type safety maintained across all platforms
- [x] Similar pattern in realtime_client.dart reviewed and fixed
Testing:
- Added test case documenting the web hot restart issue
- Verified all 98 tests pass in realtime_client package
- No functional changes, only type safety improvements
Linear: SDK-640
GitHub: #1307
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* Update packages/realtime_client/test/channel_test.dart
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
---------
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>1 parent 2210192 commit bfa480a
File tree
3 files changed
+48
-5
lines changed- packages/realtime_client
- lib/src
- test
3 files changed
+48
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
472 | 472 | | |
473 | 473 | | |
474 | 474 | | |
475 | | - | |
476 | | - | |
477 | | - | |
478 | | - | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
479 | 482 | | |
480 | 483 | | |
481 | 484 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
329 | 329 | | |
330 | 330 | | |
331 | 331 | | |
332 | | - | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
333 | 336 | | |
334 | 337 | | |
335 | 338 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
223 | 260 | | |
224 | 261 | | |
225 | 262 | | |
| |||
0 commit comments