File tree Expand file tree Collapse file tree 4 files changed +13
-11
lines changed
Expand file tree Collapse file tree 4 files changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -268,6 +268,7 @@ class SupabaseClient {
268268
269269 Future <void > dispose () async {
270270 _log.fine ('Dispose SupabaseClient' );
271+ await realtime.disconnect ();
271272 await _authStateSubscription? .cancel ();
272273 await _isolate.dispose ();
273274 _authInstance? .dispose ();
Original file line number Diff line number Diff line change 11import 'package:supabase_flutter/supabase_flutter.dart' ;
22
3- void markRealtimeClientToBeDisconnected (RealtimeClient client) {}
3+ void markRealtimeClientToBeDisconnected (SupabaseClient client) {}
44
55void disconnectPreviousRealtimeClient () {}
Original file line number Diff line number Diff line change @@ -5,25 +5,26 @@ import 'package:supabase_flutter/supabase_flutter.dart';
55@JS ()
66external JSFunction ? supabaseFlutterWSToClose;
77
8- /// Store a function to properly disconnect the previous [RealtimeClient ] in
8+ /// Store a function to properly dispose the previous [SupabaseClient ] in
99/// the js context.
1010///
11- /// WebSocket connections are not closed when Flutter is hot-restarted on web.
11+ /// WebSocket connections and [BroadcastChannel] are not closed when Flutter is hot-restarted on web.
1212///
13- /// This causes old dart code that is still associated with the WebSocket
14- /// connection to be still running and causes unexpected behavior like type
13+ /// This causes old dart code that is still associated with those
14+ /// connections to be still running and causes unexpected behavior like type
1515/// errors and the fact that the events of the old connection may still be
1616/// logged.
17- void markRealtimeClientToBeDisconnected (RealtimeClient client) {
17+ void markRealtimeClientToBeDisconnected (SupabaseClient client) {
1818 void disconnect () {
19- client.disconnect (
19+ client.realtime. disconnect (
2020 code: 1000 , reason: 'Closed due to Flutter Web hot-restart' );
21+ client.dispose ();
2122 }
2223
2324 supabaseFlutterWSToClose = disconnect.toJS;
2425}
2526
26- /// Disconnect the previous [RealtimeClient ] if it exists.
27+ /// Disconnect the previous [SupabaseClient ] if it exists.
2728///
2829/// This is done by calling the function stored by
2930/// [markRealtimeClientToBeDisconnected] from the js context
Original file line number Diff line number Diff line change @@ -11,8 +11,8 @@ import 'package:supabase_flutter/src/flutter_go_true_client_options.dart';
1111import 'package:supabase_flutter/src/local_storage.dart' ;
1212import 'package:supabase_flutter/src/supabase_auth.dart' ;
1313
14- import 'realtime_cleanup_stub .dart'
15- if (dart.library.js_interop) 'realtime_cleanup_web .dart' ;
14+ import 'hot_restart_cleanup_stub .dart'
15+ if (dart.library.js_interop) 'hot_restart_cleanup_web .dart' ;
1616
1717import 'version.dart' ;
1818
@@ -211,7 +211,7 @@ class Supabase with WidgetsBindingObserver {
211211 // flutter web hot-restart.
212212 if (kDebugMode) {
213213 disconnectPreviousRealtimeClient ();
214- markRealtimeClientToBeDisconnected (client.realtime );
214+ markRealtimeClientToBeDisconnected (client);
215215 }
216216 _widgetsBindingInstance? .addObserver (this );
217217 _initialized = true ;
You can’t perform that action at this time.
0 commit comments