fix(mobile): pause session polling in background (#9875)
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -2706,14 +2706,25 @@ export default function SessionScreen() {
|
||||
if (connState !== 'connected') {
|
||||
return
|
||||
}
|
||||
void fetchSessionTabs()
|
||||
void fetchTerminals()
|
||||
// Why: live subscription keeps stream ownership, but the fallback list poll should stop while this route is hidden.
|
||||
const interval = setInterval(() => {
|
||||
const refreshOnForeground = () => {
|
||||
if (AppState.currentState !== 'active') {
|
||||
return
|
||||
}
|
||||
void fetchSessionTabs()
|
||||
void fetchTerminals()
|
||||
}, 2000)
|
||||
return () => clearInterval(interval)
|
||||
}
|
||||
const appStateSubscription = AppState.addEventListener('change', (state) => {
|
||||
if (state === 'active') {
|
||||
refreshOnForeground()
|
||||
}
|
||||
})
|
||||
// Why: live subscription keeps stream ownership, but the fallback list poll should stop while this route is hidden or backgrounded.
|
||||
const interval = setInterval(refreshOnForeground, 2000)
|
||||
refreshOnForeground()
|
||||
return () => {
|
||||
clearInterval(interval)
|
||||
appStateSubscription.remove()
|
||||
}
|
||||
}, [connState, fetchSessionTabs, fetchTerminals])
|
||||
)
|
||||
|
||||
|
||||
@@ -29,6 +29,26 @@ describe('mobile session startup', () => {
|
||||
expect(autoCreateEffect).toContain('void handleCreateTerminal()')
|
||||
})
|
||||
|
||||
it('stops fallback list polling in the background and reconciles on resume', () => {
|
||||
const pollEffect = sliceBetween(
|
||||
"const refreshOnForeground = () => {\n if (AppState.currentState !== 'active')",
|
||||
'// Why: pick up Settings → Terminal text size on return'
|
||||
)
|
||||
|
||||
expect(pollEffect).toContain(
|
||||
"if (AppState.currentState !== 'active') {\n return\n }\n void fetchSessionTabs()"
|
||||
)
|
||||
expect(pollEffect).toContain('void fetchTerminals()')
|
||||
expect(pollEffect).toContain("AppState.addEventListener('change'")
|
||||
expect(pollEffect).toContain("if (state === 'active') {\n refreshOnForeground()")
|
||||
expect(pollEffect).toContain('const interval = setInterval(refreshOnForeground, 2000)')
|
||||
expect(pollEffect.lastIndexOf('\n refreshOnForeground()')).toBeGreaterThan(
|
||||
pollEffect.indexOf("AppState.addEventListener('change'")
|
||||
)
|
||||
expect(pollEffect).toContain('clearInterval(interval)')
|
||||
expect(pollEffect).toContain('appStateSubscription.remove()')
|
||||
})
|
||||
|
||||
it('loads session tabs without waiting for desktop activation', () => {
|
||||
const startupEffect = sliceBetween(
|
||||
'void (async () => {',
|
||||
|
||||
Reference in New Issue
Block a user