fix(supabase_flutter): simplify lifecycle reconnection with serial Future chain#1340
Merged
grdsdev merged 6 commits intoApr 2, 2026
Merged
Conversation
Contributor
|
ICYMI, I have created a PR in your fork. It removes inheritance from |
…uture chain Replace complex lifecycle reconnection logic (_disconnectFuture, _realtimeReconnectOperation, cancel flag) with a serial Future chain and target-state pattern. Operations are serialized via _pendingLifecycleOperation so disconnect and connect never overlap. _targetLifecycleState tracks the most recent lifecycle request, allowing stale operations to be skipped and reconnects to be cancelled if the app goes back to background. Add idempotency guards on both connect (isConnected) and disconnect (isConnected || isConnecting) paths. Add tests for rapid lifecycle flapping and cancellation edge cases.
…tsBindingObserver and adding AppLifecycleListener
836ed6f to
e763d1b
Compare
Two issues fixed: 1. Missing mockAppLink() in setUp — on web, Supabase.initialize() calls _appLinks.getInitialLink() via a platform channel. Without the mock, that call hangs forever, timing out the test. Native tests were unaffected because _handleInitialUri() has a kIsWeb guard. 2. The completeReadyCompleters() helper was async void, so its body ran as a deferred microtask and cleared the list. Replace with settleLifecycle() that loops until all lifecycle operations settle.
e763d1b to
7d702d0
Compare
Contributor
Author
|
@icnahom I merged your PR into it, fixed some tests, and PR is ready for review :) Thank you! |
grdsdev
approved these changes
Apr 2, 2026
Contributor
grdsdev
left a comment
There was a problem hiding this comment.
Great work @brunovsiqueira .
I think we could also use such a pattern in the token refresh logic in GoTrueClient, I think there's room for improvements there too.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #1321. Replaces the complex lifecycle state tracking (
_disconnectFuture,_realtimeReconnectOperation, cancel flag) with a serial Future chain + target-state pattern, as suggested by @icnahom in the review._pendingLifecycleOperationensures disconnect/connect never overlap_targetLifecycleStatecancels outdated operations (e.g. abort reconnect if app backgrounded again)Test plan
paused → resumed → paused → resumedflapping ends connectedpaused → resumed → pausedbefore connect completes ends disconnectedsupabase_fluttertest suite passesdart formatanddart analyzeclean