Prevent dataset mismatch: UI deployment doesn't reflect sanity.json changes

9 replies
Last updated: Aug 13, 2021
A true story of a bone-headed mistake, one that could be easily avoided with any of several minor enhancements to the UI or its hosting.
We have two datasets:
development and production. The one UI deployment we’re allowed normally points at production. When chasing down an issue I thought might be build / hosting related, I changed the environment in sanity.json to point to development. When done testing, I changed sanity.json back to production, _but I forgot to re-deploy the UI_*.* Later, another user logged in and added some data, but it didn’t appear in our app. It was 100% my mistake, but here are some thoughts on how sanity.io could have my back to help prevent such mistakes:
• Support a parameterized URL for hosting the URL. Instead of just supplying the subdomain name,
acme, allow acme-{dataset}. Then, if the UI is configured for production, the URL would become acme-production.sanity.io . If, as I did, the UI is deployed configured to
development
, the url would become become acme-development.sanity.io .• Allow UI hosting per dataset. Charge a nominal fee for it, but then there would be two URLs for our hosting:
myApp-production.sanity.io and myApp-development.sanity.io • Bake in a default UI indicator as to which dataset is being used. This could be enabled and/or overridden by configuration (e.g.
showDatasetIndicator=[false|true]
)
AI Update

I feel your pain – this is a classic mistake that's bitten many developers! The good news is that Sanity does support patterns that can prevent this exact scenario, though they might not be immediately obvious.

Multiple Studio Deployments (Already Possible!)

Your second suggestion is actually already supported. You can deploy multiple Studio instances to different subdomains on Sanity's hosting, each permanently configured for a specific dataset. This is the recommended approach and doesn't cost extra.

Here's how it works: When you run sanity deploy, you're prompted to choose a hostname. You can deploy multiple times with different configurations:

# In your sanity.config.ts, use environment variables
export default defineConfig({
  projectId: 'your-project-id',
  dataset: process.env.SANITY_STUDIO_DATASET || 'production',
  // ... rest of config
})

Then deploy separate instances:

# Deploy production Studio
SANITY_STUDIO_DATASET=production sanity deploy
# When prompted, enter hostname: acme-production

# Deploy development Studio  
SANITY_STUDIO_DATASET=development sanity deploy
# When prompted, enter hostname: acme-development

This gives you acme-production.sanity.studio and acme-development.sanity.studio as permanent, separate URLs. Each deployment is locked to its dataset configuration – no chance of forgetting to redeploy because you never change the production Studio's config. This approach is covered in the multi-environment deployments guide and the setting up your environments course.

Dataset Indicator in the UI

For a visual safety net, you can add a banner showing which dataset is active. Using Studio's configuration API with defineConfig, you can customize the navbar:

import { defineConfig } from 'sanity'

const datasetBanner = () => {
  const dataset = process.env.SANITY_STUDIO_DATASET || 'production'
  return (
    <div style={{
      background: dataset === 'production' ? '#f03e2f' : '#f59e0b',
      color: 'white',
      padding: '8px',
      textAlign: 'center',
      fontWeight: 'bold',
      fontSize: '14px'
    }}>
      ⚠️ {dataset.toUpperCase()} DATASET
    </div>
  )
}

export default defineConfig({
  // ... your config
  studio: {
    components: {
      navbar: (props) => (
        <>
          {datasetBanner()}
          {props.renderDefault(props)}
        </>
      )
    }
  }
})

There are also community plugins that add environment badges, though you'll want to verify Studio v3 compatibility.

The Real Solution: Never Change Production Config

The best practice combines both approaches:

  1. Deploy separate Studios for each environment – your production Studio at acme-production.sanity.studio is permanently configured for production, eliminating the "forgot to redeploy" problem entirely
  2. Use environment-specific .env files locally (.env.development, .env.production) so developers automatically work with the right dataset when running sanity dev or sanity build
  3. Add visual indicators as an extra safety layer

This way, there's no deployment step that could be forgotten. Your team always knows which URL to use, and the mistake you experienced becomes architecturally impossible.

What About Workspaces?

You might also consider Workspaces, which let you configure multiple datasets within a single Studio deployment with a built-in switcher. However, this doesn't solve your specific problem – you'd still need to remember to deploy after changing configuration. Workspaces are better suited for multi-tenant scenarios or when you want editors to easily switch between datasets, not for preventing deployment mistakes.

The separate deployment approach is really the gold standard here – it turns your configuration mistake into an impossibility rather than relying on memory or visual cues.

Show original thread
9 replies
Sorry that bit you Jack. I think several of these are good suggestions!
I’ll make product aware of this. Thank you.
user M
Your suggestion was my first thought. Unfortunately, there’s a strange little bug that kept it from working for me. See https://sanity-io-land.slack.com/archives/C01KGNW4MT8/p1628776408006800
I’ll check out the Spaces feature as an option. Thanks!
We can look into the env issue as something seems off there indeed - thanks for sharing!
I'd be curious to know whether using the built-in client config gives you any different results here, if you wouldn't mind trying? The code would look as follows (without environment variables):

import React from 'react'
import client from 'part:@sanity/base/client'
const { dataset } = client.config()

const Logo = () => {
  const styles = {margin: 0, textAlign: 'center'}

  return <div><img src="/static/logo.jpg" alt="the logo" /><p style={styles}>Dataset: {dataset}</p></div>
}

export default Logo
user M
That worked awesomely! I got the label Dataset: production displaying under the logo. I then changed the
.env.production
file to
SANITY_STUDIO_API_DATASET=development
redeployed, and Voila! The label read
Dataset: development. Checking the data, it was no illusion. The dataset indicated was the dataset being used.
Thanks!
That's great to hear! Thanks for checking it in combination with env variables too 🙂
That's great to hear! Thanks for checking it in combination with env variables too 🙂
Thanks for the help. This will go a long way toward saving me from myself! 🙂

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.

Was this answer helpful?