Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions sync/streams/client-usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,33 @@ await db.Connect(connector, new ConnectOptions {
</Tab>
</Tabs>

## Opting Out of Auto-Subscribed Streams

By default, every stream defined with [`auto_subscribe: true`](/sync/streams/overview#using-auto-subscribe) starts syncing as soon as the client connects. In some cases you may want to control this from the client — for example, to defer syncing reference data until the user has signed in to a specific workspace, or to keep storage minimal on lower-tier devices.

<Note>
This option is currently only available in the Swift SDK. In other SDKs, auto-subscribed streams always sync on connect; remove `auto_subscribe: true` from the stream definition and use explicit subscriptions if you need on-demand control.
</Note>

<Tabs>
<Tab title="Swift">
Set `includeDefaultStreams: false` on `ConnectOptions` to skip auto-subscribed streams. Streams the client subscribes to explicitly via `db.syncStream(...).subscribe()` continue to sync as normal.

```swift
// Connect, but don't sync streams that have `auto_subscribe: true`
try await db.connect(
connector: connector,
options: ConnectOptions(includeDefaultStreams: false)
)

// Explicit subscriptions still work
let sub = try await db.syncStream(name: "list_todos", params: ["list_id": JsonValue.string("abc")]).subscribe()
```

The default is `true`, which preserves the existing behavior of syncing every auto-subscribed stream on connect.
</Tab>
</Tabs>

## API Reference

For quick reference, here are the key methods available in each SDK:
Expand Down
4 changes: 4 additions & 0 deletions sync/streams/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ streams:
AND order_id IN (SELECT id FROM orders WHERE user_id = auth.user_id())
```

<Note>
Clients using the Swift SDK can opt out of auto-subscribed streams at connect time with `ConnectOptions(includeDefaultStreams: false)`. See [Opting out of auto-subscribed streams](/sync/streams/client-usage#opting-out-of-auto-subscribed-streams) for details.
</Note>


## Client-Side Usage

Expand Down