Skip to content

Conversation

@vanpelt
Copy link
Collaborator

@vanpelt vanpelt commented Nov 9, 2025

Problem

When users navigated away from the app during an SSE connection to a codespace, iOS would suspend the URLSession connection. Upon returning to the app, the connection would remain stuck in a "connecting" state indefinitely, never completing or showing an error.

Solution

Added app lifecycle monitoring using SwiftUI's scenePhase environment value. When the app is backgrounded during an active SSE connection, the view now tracks this state. Upon returning to the foreground, it automatically disconnects the stale connection and initiates a fresh SSE connection to the same codespace.

Implementation

  • Added @Environment(\.scenePhase) to monitor app state transitions
  • Tracks connection state with wasConnectingBeforeBackground flag
  • Stores pendingCodespaceName to preserve the target codespace across app backgrounding
  • Implements handleScenePhaseChange() to detect background→active transitions and trigger reconnection
  • Uses SwiftUI-native approach instead of NotificationCenter for better integration with view lifecycle

@vanpelt vanpelt merged commit 9fef98f into main Nov 12, 2025
6 checks passed
@vanpelt vanpelt deleted the fix/sse-reconnect-on-foreground branch November 12, 2025 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants