🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Suggestions for avoiding bone-headed mistakes in Sanity.io deployments

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]
)
Aug 12, 2021, 9:24 PM
Sorry that bit you Jack. I think several of these are good suggestions!
Aug 12, 2021, 10:35 PM
I’ll make product aware of this. Thank you.
Aug 12, 2021, 10:35 PM
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
Aug 13, 2021, 2:25 PM
I’ll check out the Spaces feature as an option. Thanks!
Aug 13, 2021, 2:26 PM
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
Aug 13, 2021, 2:58 PM
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!
Aug 13, 2021, 3:32 PM
That's great to hear! Thanks for checking it in combination with env variables too 🙂
Aug 13, 2021, 3:48 PM
That's great to hear! Thanks for checking it in combination with env variables too 🙂
Aug 13, 2021, 3:48 PM
Thanks for the help. This will go a long way toward saving me from myself! 🙂
Aug 13, 2021, 3:49 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?