useRefreshSubscriptions

Re-issue every live subscription after the connection's subject changes — no reload, no reconnect.

When a user signs in, the server rebinds the subject on the existing connection. Every open subscription is now snapshotting against the wrong subject's tenant scope. Reloading the page would fix it and lose everything else; this hook is the surgical version.

import { useRefreshSubscriptions } from '@voltro/client'

const refresh = useRefreshSubscriptions('app')
await signIn(...)
refresh()

It returns a stable zero-argument function. Calling it interrupts each active subscription's fiber and re-forks it over the same WebSocket — no reconnect. Server-side each one is a fresh subscription, so it flows through the auth middleware again and resolves the new subject.

Optimistic patches survive the refresh: they are tied to mutation lifecycles, not subscription lifecycles, and the new snapshots land underneath them.

The data does not — each entry's rows are cleared and the components go back to loading until their new snapshot arrives. That is deliberate: the whole reason to call this is that the identity changed, and the new subject may be entitled to strictly less than the old one. It is the same boundary that stops a reconnect from seeding across a useReconnect() — a dropped connection keeps your screen, a change of identity clears it.

This is not a cache-invalidation tool. Subscriptions are already live, so a normal write needs no refresh — reach for this only when the connection's identity changed underneath them.

Refresh one snapshot query

useRefreshSubscription(apiName, tag, input) refreshes one active query input while retaining its displayed data and optimistic patches. Use it for computed snapshots of external services that have no reactive dependency. Ordinary database subscriptions already update automatically.

import { useRefreshSubscription } from '@voltro/client'

const refreshSnapshot = useRefreshSubscription('app', 'external.status', { region: 'eu' })
refreshSnapshot()

The callback is stable for equivalent inputs and stays bound to that input. It returns false when there is no active subscription, the initial read is pending, or a refresh is already pending. Otherwise it starts a fresh read and returns true. Switching the input does not refresh unrelated queries. Do not use this to change authentication identity: use useRefreshSubscriptions for that.