You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Three fixes to sanity-rooms:
1. SyncClient hydration: initialState is now optional. Client connects
immediately, hydrates from the server room's first state message.
ready promise, isHydrated getter, mutation guards before hydration.
Editor no longer needs an HTTP pre-fetch for initial config.
2. Ref doc creation: editDocument fails on non-existent docs (SDK
learnings were wrong — proved with throwaway script). Bridge now
uses createDocument + editDocument for new ref docs, tracks known
docs via markRefDocKnown to avoid duplicate creates. Mock updated
to enforce real SDK constraints.
3. Defer incomplete refs: handleSanityChange now skips mapping when
ref bridges haven't loaded yet, preventing broadcast of state with
stripped custom resources. Ref bridge onChange re-triggers mapping
once loaded.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: sanity-sdk-learnings.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,9 +55,10 @@ When you subscribe to a doc via `getDocumentState`, the SDK creates an entry in
55
55
### `editDocument` vs `createDocument`
56
56
57
57
-`createDocument` throws if a draft already exists (`"A draft version already exists"`)
58
-
-`editDocument` with `{ set: fields }` works as an **upsert** — it creates the draft if it doesn't exist, updates it if it does. This is the correct choice for ref documents (custom fonts, palettes, backgrounds) where the doc may or may not exist.
58
+
-`editDocument`**requires the doc to exist** in draft or published form — it throws `"Cannot edit document because it does not exist in draft or published form"` otherwise. It is NOT an upsert.
59
+
-`createDocument` + `editDocument` in the same `applyDocumentActions` batch WORKS — the create runs first, then the edit sees the newly created draft.
59
60
60
-
**Use `editDocument` for ref docs, not `createDocument`.**Using`createDocument` in a batch with the main doc edit causes the entire batch to fail if the ref doc draft already exists — silently dropping the main doc write too.
61
+
**For ref docs that may or may not exist:**batch`createDocument(handle)` before `editDocument(handle, { set: ... })`. If the doc already exists, skip the `createDocument`. The bridge must track which ref docs have been created to choose the right action.
0 commit comments