
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI can see you're dealing with two issues here: the GROQ query not properly dereferencing links in markDefs, and a UI issue with double-clicking in Studio. Let me help you troubleshoot both.
Looking at your query output, the markDefs array in your body is not being expanded properly - it's showing the reference object {"_ref": "...", "_type": "reference"} instead of the resolved slug. The issue is that markDefs lives inside each block within the body array, not at the top level of your query.
Your current query structure has the markDefs expansion outside and separate from the body[] projection. You need to move it inside the body projection. Based on this community answer about resolving references in Portable Text, you need to use the @ operator to reference the current scope when dealing with references inside arrays.
Try this corrected structure:
*[_type == "post"][7] {
title,
slug { current },
publishedAt,
"author": author->name,
mainImage,
"categories": categories[]->title,
"website": website->webName,
body[]{
...,
asset->{
...,
"_key": _id
},
_type == "productTable" => {
"productImg1": @.productImage1.asset->url,
"productImg2": @.productImage2.asset->url,
"productImg3": @.productImage3.asset->url,
"productImg4": @.productImage4.asset->url,
},
markDefs[]{
...,
_type == "refLink" => {
"slug": @.reference->slug
},
_type == "extLink" => {
"href": @.href
}
}
}
}The key changes:
markDefs[] inside the body[]{} projection@.reference->slug to dereference the internal link (the @ operator refers to the current markDef object)@.href since they typically don't have referencesAccording to the Portable Text annotations documentation, each block has its own markDefs array, so you need to expand it at the block level.
The "Invalid block value" error and needing to click twice to open link options sounds like a schema configuration issue. A few things to check:
marks.annotations arrayYour refLink and extLink should each be defined something like:
defineType({
name: 'refLink',
type: 'object',
title: 'Internal Link',
fields: [
{
name: 'reference',
type: 'reference',
to: [{type: 'post'}] // or whatever document types you're linking to
}
]
})Then in your block content schema:
marks: {
annotations: [
{name: 'refLink', type: 'refLink'},
{name: 'extLink', type: 'extLink'}
]
}The "Invalid block value" message typically means the data structure being created doesn't match what your schema expects. Check your browser console for any schema validation warnings when you're editing - they'll give you more specific clues about what's mismatched.
If you're still seeing issues after these changes, share your schema definitions for refLink and extLink and I can help spot any configuration problems!
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store