
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeThis is likely happening because you have Stega encoding enabled in your Sanity client! Stega is a feature that invisibly embeds metadata into your content strings using zero-width UTF-8 characters to power Visual Editing features.
When Stega encoding is active (usually in preview/draft mode), Sanity automatically appends invisible characters to strings in your fetched data. These characters contain Content Source Map metadata that enables click-to-edit overlays in the Presentation tool. To users, the text looks normal, but the zero-width spaces are actually there in the string data.
If you're not using Visual Editing features, you can disable Stega in your client configuration:
import { createClient } from '@sanity/client'
export const client = createClient({
projectId: 'your-project-id',
dataset: 'your-dataset',
apiVersion: '2024-01-01',
useCdn: true,
stega: { enabled: false } // Disable stega encoding
})Or if you're using @sanity/client/stega, switch to the regular client import:
// Instead of this:
import { createClient } from '@sanity/client/stega'
// Use this:
import { createClient } from '@sanity/client'If you need Stega for preview mode but it's interfering with your business logic, use the vercelStegaSplit or vercelStegaCleanAll utilities from @vercel/stega:
import { vercelStegaSplit } from '@vercel/stega'
export function MyComponent({ text }) {
const { cleaned, encoded } = vercelStegaSplit(text)
// Use 'cleaned' for business logic
if (cleaned === 'some-value') {
// Your logic here
}
// Render both to preserve Visual Editing
return (
<div>
{cleaned}
<span style={{ display: 'none' }}>{encoded}</span>
</div>
)
}For cleaning entire objects:
import { vercelStegaCleanAll } from '@vercel/stega'
const cleanedData = vercelStegaCleanAll(yourData)As noted in the troubleshooting documentation, Stega characters can cause issues with:
if (value === 'expected') will fail)<ReactWrapBalancer>The key is to clean the strings before using them in business logic while preserving the encoded versions for Visual Editing to work properly.
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