Browse documentation

silent() (deprecated)

Deprecated. Do not use silent() for new code.

silent() suppresses subscriber notifications during synchronous state mutations. It does not freeze the external-store snapshot React reads.

import { silent } from '@comwit/state'

Why it is deprecated

React's useSyncExternalStore compares snapshots before commit even when no listener fires. A render-time mutation can therefore invalidate and restart the render tree indefinitely:

// Do not do this.
function PostInit({ post }: { post: Post }) {
  const actions = usePost((state) => state.actions)
  actions.init(post) // silent() inside init does not make this render-safe
  return null
}

Use ordinary reactive actions for user events and imperative workflows. For a query fetched during SSR, await the server function in a Server Component and initialize the cache in a small client route adapter:

function PostRoute({ slug, initialPost }: Props) {
  usePost.hydrate({ detail: { arg: slug, data: initialPost } })
  return <PostView />
}

hydrate() runs before the route's normal domain-hook read and initializes the missing query entry without an action, public proxy mutation, or subscriber suppression. Experimental .suspend() is not the default SSR migration path and cannot call a Next.js Server Function during initial client render.

Legacy behavior

Existing synchronous calls remain supported for compatibility, including nested calls. Async callbacks are not supported. Prefer normal mutations so mounted consumers observe every committed change.