
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeThis is a common issue! The editing overlays are showing in production because stega encoding and the Visual Editing component are still active on your production site. They should only be enabled when Draft Mode is active.
The overlays you're seeing are powered by stega encoding (invisible metadata embedded in your content) and the <VisualEditing> component from next-sanity or @sanity/overlays. If these are running unconditionally in production, visitors will see the editing overlays.
You need to conditionally enable both stega encoding and the VisualEditing component only when Draft Mode is active. Here's how:
When creating your Sanity client, only enable stega in draft mode:
import { createClient } from 'next-sanity'
import { draftMode } from 'next/headers'
export async function getClient() {
const { isEnabled } = await draftMode()
return createClient({
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET,
apiVersion: '2024-01-01',
useCdn: !isEnabled,
perspective: isEnabled ? 'previewDrafts' : 'published',
stega: {
enabled: isEnabled, // Only enable stega in draft mode
studioUrl: '/studio',
},
})
}In your root layout or component, only render the <VisualEditing> component when in draft mode:
import { draftMode } from 'next/headers'
import { VisualEditing } from 'next-sanity'
export default async function RootLayout({ children }) {
const { isEnabled } = await draftMode()
return (
<html>
<body>
{children}
{isEnabled && <VisualEditing />}
</body>
</html>
)
}Make sure you have proper Draft Mode API routes set up to enable/disable the preview state. You should have routes like:
/api/draft - to enable draft mode/api/disable-draft - to exit draft modedraftMode().isEnabled is true<VisualEditing> component only rendered in draft modepublished perspective in productionAfter making these changes, your production site should no longer show editing overlays to regular visitors, while content editors using preview URLs will still get the full visual editing experience with the Presentation tool.
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