Skip to content

Conversation

@Yves000
Copy link

@Yves000 Yves000 commented Oct 26, 2025

Summary

Implements automatic resubscription of queries when network connectivity is restored, fixing the infinite loading spinner issue after network interruptions.

Features

  • NetworkMonitor using Network.framework for connectivity detection (iOS 13.0+, macOS 10.15+)
  • Automatic subscription tracking in ConvexClient
  • Subscriptions automatically reestablish when network reconnects
  • Manual reconnect() API for app lifecycle integration
  • Works seamlessly with WiFi↔Cellular, airplane mode, Mac sleep/wake
  • Thread-safe subscription tracking with NSLock

Changes

  • Add NetworkMonitor class for network path monitoring
  • Add subscription tracking to ConvexClient (UUID-based)
  • Extend subscribe() to register and track active subscriptions
  • Implement resubscribeAll() for automatic reconnection
  • Add public reconnect() method for manual control
  • NetworkMonitor disabled for test clients to avoid test flakiness
  • Add comprehensive tests for reconnection scenarios
  • Update README with reconnection documentation
  • Update CHANGELOG with detailed feature description

API Documentation

Added comprehensive DocC documentation for the new reconnect() public API:

/// Manually reconnects all active subscriptions. /// /// The client automatically monitors network connectivity and reconnects /// subscriptions when the network is restored, so manual reconnection is /// typically not needed. public func reconnect()

Testing

  • ✅ All 22 unit tests pass
  • ✅ All 10 integration tests pass
  • ✅ NetworkMonitor only runs in integration tests (not unit tests)
  • ✅ Tested on iOS Simulator and macOS

Fixes

  • Critical: Infinite loading spinner after Mac laptop sleep/wake
  • Critical: Subscriptions not updating after WiFi disconnect/reconnect
  • Data not refreshing after network state changes
  • Missing reconnection handling reported by Discord users

Dependencies

This PR builds on top of #6 (JWT Token Refresh). It can be reviewed independently but should be merged after #6.

🤖 Generated with Claude Code

Yves000 and others added 2 commits October 26, 2025 10:17
Implements automatic token refresh to prevent authentication errors in long-running apps. Tokens are proactively refreshed 60 seconds before expiration. Features: - TokenRefreshManager monitors JWT expiration and auto-refreshes - AuthProviderError enum for standardized auth error handling - Default AuthProvider.refreshToken(from:) throws refreshNotSupported - Providers can opt-in by implementing refreshToken(from:) - Auto-logout on refresh failure for better UX - Uses Timer instead of Task.sleep for iOS Simulator reliability Changes: - Add JWTDecoder helper for extracting token expiration - Add TokenRefreshManager class for refresh orchestration - Extend AuthProvider protocol with optional refreshToken method - Add comprehensive tests for refresh scenarios - Update README with token refresh documentation - Add CHANGELOG documenting breaking/non-breaking changes Non-breaking: Existing AuthProviders continue to work without changes. Providers that don't support refresh will use default implementation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Implements automatic resubscription of queries when network connectivity is restored, fixing the infinite loading spinner issue after network interruptions. Features: - NetworkMonitor using Network.framework for connectivity detection (iOS 12.0+) - Automatic subscription tracking in ConvexClient - Subscriptions automatically reestablish when network reconnects - Manual reconnect() API for app lifecycle integration - Works seamlessly with WiFi↔Cellular, airplane mode, Mac sleep/wake - Thread-safe subscription tracking with NSLock Changes: - Add NetworkMonitor class for network path monitoring - Add subscription tracking to ConvexClient (UUID-based) - Extend subscribe() to register and track active subscriptions - Implement resubscribeAll() for automatic reconnection - Add public reconnect() method for manual control - NetworkMonitor disabled for test clients to avoid test flakiness - Add comprehensive tests for reconnection scenarios - Update README with reconnection documentation - Update CHANGELOG with detailed feature description Fixes: - Infinite loading spinner after Mac laptop sleep/wake - Subscriptions not updating after WiFi disconnect/reconnect - Data not refreshing after network state changes - Missing reconnection handling reported by Discord users 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
@dowski
Copy link
Contributor

dowski commented Oct 29, 2025

Similar to my thoughts on #6, closing this PR.

@dowski dowski closed this Oct 29, 2025
@dowski
Copy link
Contributor

dowski commented Oct 29, 2025

I'll note that for this functionality in particular, I would advocate for pushing the logic further down the stack into the Rust layer so any clients built off of it would benefit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants