Sanity Library Reference Docs
    Preparing search index...
    • Ensures a document representation exists where the engine's read perspective will find it, so $fields.subject hydrates at start instead of resolving to "document unavailable".

      The read perspective mirrors the engine's field resolution: a release-bound instance reads under [releaseName] — the release's version docs over published, drafts invisible — otherwise drafts-over-published. The write matrix follows from it:

      • a visible representation already exists → no write
      • release-bound with only a draft → the version doc is created from the draft, a server-side copy, so the editor's content is what lands
      • nothing exists → initialValue (or a bare typed doc) becomes the draft or version doc

      Every write rides createVersion, so the promise resolves only once the write is committed and callers may start the workflow the moment it settles. Probe-then-write is racy: two concurrent starts can both observe "missing" and both write, and the lake rejects the loser. A failed write re-runs the probe, resolving if a visible representation exists by then; if the target is still missing, the original error surfaces.

      Returns Promise<void>