anomalyco / anomalyco/opencode
Mobile browser tab does not reconnect SSE stream after returning from another app
@Brendonovich is already working on this.
Since Jul 27, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
When accessing opencode serve or opencode web from a mobile browser (Chrome Android), switching to another app and coming back leaves the chat interface frozen. No new messages appear until the user manually refreshes the page.
Steps to reproduce
- Run
opencode serve --hostname 0.0.0.0 - Open the web interface in Chrome on an Android phone
- Start a conversation that generates a long response
- Switch to another app (e.g. WhatsApp, settings, etc.)
- Wait a few seconds
- Switch back to Chrome
Expected behavior
The chat should show any new messages that arrived while the tab was backgrounded.
Actual behavior
The chat remains frozen at the last state before switching apps. Only a manual page refresh (F5 or pull-to-refresh) updates the interface.
Root cause
The SSE event stream in packages/app/src/context/server-sdk.tsx only handles tab lifecycle via pagehide/pageshow events, which are designed for bfcache (back-forward cache) navigation. On mobile:
pagehideoften does not fire when a tab is backgrounded by switching apps- When it does fire, it calls
stop()which aborts the SSE connection and may cancel server-side response generation pageshowfires withevent.persisted=falseon return (not a bfcache restore), so the existing handler does nothing
The fix should listen to document.visibilitychange to reconnect the SSE stream when the tab becomes visible again.
Environment
- OpenCode version: 1.17.20+
- Device: Android phone (Chrome browser)
- Server:
opencode serveon Linux
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.