fix(auth,supabase): recover from client corruption after tab suspension#2228
Open
KrunchMuffin wants to merge 1 commit intosupabase:masterfrom
Open
fix(auth,supabase): recover from client corruption after tab suspension#2228KrunchMuffin wants to merge 1 commit intosupabase:masterfrom
KrunchMuffin wants to merge 1 commit intosupabase:masterfrom
Conversation
After a browser tab is suspended for several minutes (common in PWAs, mobile browsers, and Safari), the Supabase client could enter an irrecoverable corrupted state where auth.getSession() returns null, functions.invoke() hangs, and realtime channels fail silently. Root cause: when _recoverAndRefresh fails with a retryable error (e.g. network still reconnecting after tab resume), no auth event was emitted, leaving realtime and functions with a stale/expired token. Additionally, the next auto-refresh tick could be up to 30 seconds away. Changes: **auth-js (GoTrueClient):** - Emit SIGNED_IN with current session on retryable refresh failure so downstream listeners (realtime, functions) can re-sync immediately - Trigger an immediate auto-refresh tick after visibility change recovery instead of waiting up to 30s for the next scheduled tick **supabase-js (SupabaseClient):** - Add visibilitychange listener that force-syncs a fresh token to the realtime client when the tab resumes, as a safety net for cases where the auth event bridge misses the token update Closes supabase/supabase#36046 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
This looks solid. Nice work dude. |
Contributor
|
The reason why I do not want to merge this PR (or similar PRs) is that they are patching a deeper issue with how we use the Web Lock API and navigator locks. We have discussed this internally with the team quite a lot. While we appreciate all your contributions, we do want to come up with a solution to the root of the problem. |
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
Fixes the Supabase client becoming irrecoverably corrupted after browser tab suspension (2-5+ minutes), which affects PWAs, mobile browsers, and long-lived sessions. After resuming:
auth.getSession()could returnnulldespite a valid session in storagefunctions.invoke()could hang indefinitely (blocked on lock-gatedgetSession)Root cause: When
_recoverAndRefreshfails with a retryable error (e.g. network still reconnecting after tab resume), no auth event was emitted, leaving realtime and functions permanently desynchronized. The next auto-refresh tick could be up to 30 seconds away.Changes
auth-js (
GoTrueClient):SIGNED_INwith current session on retryable refresh failure so downstream listeners (realtime, functions) can re-sync immediately instead of silently dropping the error_autoRefreshTokenTick()after visibility change recovery instead of waiting up toAUTO_REFRESH_TICK_DURATION_MS(30s) for the next scheduled ticksupabase-js (
SupabaseClient):visibilitychangelistener that force-syncs a fresh token to the realtime client when the tab resumes — acts as a safety net for cases where the auth event bridge misses the token updateTest plan
should sync fresh token to realtime on visibility change (tab resume)in SupabaseClient testsRelated
Closes supabase/supabase#36046
🤖 Generated with Claude Code