See Sanity in action 👀 Join us for a live product demo + Q&A →
Experimental feature

Spaces

Switch between datasets in the Studio

Spaces lets you quickly switch between datasets in the studio. This may be useful when:

  • Managing multiple departments within the same organization, each with their own, separate datasets, but all sharing the same schema.
  • Modifying an existing schema type and testing how it works using a staging dataset.

A “space” is simply a mapping from a name/title to an API config. Spaces can be configured in your studio's sanity.json (under the __experimental_spaces key). Here's an example:

{
  "project": {
    "name": "Studio with spaces"
  },
"__experimental_spaces": [
{ "name": "production", "title": "Prod", "default": true, "api": { "projectId": "ppsg7ml5", "dataset": "production" } }, { "name": "staging", "title": "Staging", "api": { "projectId": "ppsg7ml5", "dataset": "staging" } } ], // The rest of your sanity.json configuration }

This will render a dropdown to switch between spaces in the studio. The rest of your sanity.json configuration ("plugins", "parts", etc.) can be added per usual.

Switching to another space will connect to the dataset configured for that space.

Gotcha

Enabling spaces will add the dataset name to the Studio’s URL-scheme. This will potentially break deep links and bookmarks to the Studio.

From:

<yourname>.sanity.studio/desk/<types-and-ids>

To:

<yourname>.sanity.studio/<datasetname>/desk/<types-and-ids>

Accessing the currently selected dataset

Throughout your Studio you may wish to conditionally render items based on the current dataset name.

It is possible to find the currently targeted dataset name by importing the client. In this example, we mark the seo object field hidden if the current dataset is not production.

import sanityClient from 'part:@sanity/base/client'

const client = sanityClient.withConfig({apiVersion: `2021-03-25`})

export default {
  name: 'seo',
  title: 'SEO',
  type: 'object',
  hidden: () => client.config().dataset !== 'production',
  fields: [
    // ...fields
  ],
}

Gotcha

Administering multiple projects with __experimental_spaces does not currently work. You'll have to run separate studios to access separate projects.

Disclaimer: Experimental feature

This feature is still considered experimental, although it has been out for a while. We'll make sure to have a documented upgrade path for it that doesn't require too much work. If you need this feature, you can safely use it for the time being.

Was this article helpful?