---
title: "Recipe: keep a desktop feed and release it before suspension"
description: "A WebSocket feed that stays open while a desktop window is hidden and closes when the host freezes the page."
modificationDate: "2026-11-19"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Recipe: keep a desktop feed and release it before suspension

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/recipes/suspending-feed: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

Gate the resource on execution eligibility, so hiding a desktop window keeps
its socket while a host's freeze transition releases it in the same commit.

```prompt Release my live feed before the app is suspended
Make the Exact app in this folder keep its feed's socket while a desktop window is hidden, and release it when the host freezes the page. Use https://github.com/expo/exact/blob/main/docs/recipes/suspending-feed.md as the source for each step. The Exact checkout has the same page at docs/recipes/suspending-feed.md.

1. If this folder is not an Exact app (it has no exact.mjs and app.contract), stop and tell me.
2. If I did not say which feed, ask me: the resource in app.contract that holds its socket, or my service's WSS endpoint if the app has no feed yet. Ask me whether the feed's data is sensitive: the last answer stays visible unless the resource is `transient`.
3. In app.contract, read `exactPage()` as a resource whose shape has `frozen: bool`, and gate the feed's resource with `when not page.frozen`. Do not gate it on visibility: a hidden desktop window keeps its socket.
4. In app.ts, grant `net.websocket` for my service's origin, and answer the source with a `fetch` that has `exactStream`, as the recipe shows. Write no cleanup task: when the gate closes, the host cancels the request and closes the socket. When the gate reopens, the resource asks again and opens a fresh socket.
5. Add `transient` to the resource if I said the data is sensitive. Save the person's changes as they happen, and handle reconnection: a browser promises nothing after hidden, and no lifecycle notification guarantees that a final send finishes.
6. Add a test in app.test.contract that drives the transition with `prefer frozen true`, then `prefer frozen false`, and a test that shows `prefer visibility-state hidden` alone keeps the stream open. Ask me before a test opens my real service.
7. Follow the platform checks in docs/start-here.md (`bun exact.mjs docs platform checks`) for the targets in the app's AGENTS.md and app.json until they pass. Read the reports, including counted findings; a zero exit code alone does not mean clean. Fix the app, not the test. These tests check the plan's policy, not the host's timing. If a finding stays after three rounds of fixes, or the app had it before you changed anything, record it (step 8) and report it; do not keep trying.
8. When a doc was wrong or missing, or a step needed a workaround, read `bun exact.mjs feedback status`. Under `never`, keep no note. Otherwise record it: `bun exact.mjs feedback note "<what happened>"`, which goes to Expo only as that status says. Do not change the policy; tell me how many notes you kept.
9. Tell me the gate you wrote, what the tests and checks reported, and what I must still do on a device: qualify the host's timing before I rely on it. On macOS, Linux and Windows desktops, `frozen` stays false even with a hidden window.
```

```contract
shape Page
  frozen: bool

component App
  resource page = exactPage() as shape Page
  resource feed = events() when not page.frozen as shape string else empty()
  view
    text feed testId="feed"
```

```ts
import type { Answer } from './app.contract.d.ts';

export const grants = 'net.websocket wss://feed.example.com';
export const answer: Answer = (source) => {
  if (source !== 'events') throw new Error('Unknown source: ' + source);
  return fetch('wss://feed.example.com/events', {
    exactStream: (event) => event.type === 'message' ? String(event.data) : event.type,
  });
};
```

Replace the endpoint and grant with your service's. Closing the gate lets the
stream go; the host cancels its request and closes the socket. No cleanup task
has to finish. The last answer stays visible, and reopening the gate asks again
and opens a fresh socket. Resources default to kept answers; add `transient`
for sensitive feed data.

On macOS, Linux and Windows desktops `frozen` stays false even with a hidden window.
Android sets it when the activity is stopped and no promoted foreground service
carries a live claim or plays media. iOS and tvOS set it in the background unless
active audio with the background audio mode keeps execution eligible. A configured playback category alone grants
nothing; ending playback while hidden freezes the page. A signed-phone run remains owed.
On the web it follows Page Lifecycle `freeze`/`resume` where fired, else false.
A browser promises nothing after hidden: save as changes happen and handle
reconnection; no lifecycle notification guarantees a final send will finish.

Drive the transition with `prefer frozen true`, then `prefer frozen false`.
`prefer visibility-state hidden` alone should keep the stream open. This checks
the plan's policy; qualify the host's timing on a device before relying on it.
