How to resolve references in Sanity preview context?
Based on the documentation you're referencing about preview content, when you're working with references in Sanity's visual editing setup, you'll need to dereference and expand references in your GROQ query rather than trying to resolve them client-side in the preview object.
The Solution: Use GROQ Projections
When fetching data for preview, you need to dereference references using the -> operator in your GROQ query:
*[_type == "yourDocumentType"] {
_id,
property,
"nestedProperty": property->nestedProperty
}Or if you want the entire referenced document:
*[_type == "yourDocumentType"] {
_id,
property,
propertyExpanded: property->
}Why This Matters for Visual Editing
The preview content passed to your components needs to have references already resolved because:
- Content Source Maps need to track the full path through dereferenced content for click-to-edit functionality
- The preview system doesn't have a built-in client-side reference resolver (no separate ReferenceResolver API)
- Your queries should return the complete data shape your components expect
Example Pattern
If your document structure is:
{
_type: "page",
author: {
_type: "reference",
_ref: "author-123"
}
}Your GROQ query for preview should be:
*[_type == "page"] {
_id,
title,
"authorName": author->name,
"authorBio": author->bio,
// Or get the whole author object:
authorFull: author->
}For Visual Editing Specifically
When using the Presentation tool or fetching content for visual editing, make sure your data-fetching functions include these projections. The dereferencing happens at query time on Sanity's CDN, not in your preview components.
If you're using @sanity/client with useLiveQuery or similar hooks, the dereferenced data will flow through automatically to your components with proper Content Source Maps for the visual editing overlays.
The key takeaway: resolve references in your GROQ queries using ->, not in your component code. The preview object you receive should already have the nested data you need. This is the standard pattern for working with references in Sanity - there's no separate client-side resolver API needed.
Show original thread4 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.