Sanity Spaces "default" key not working to set default dataset

8 replies
Last updated: Apr 15, 2022
hi, we are using the Spaces feature to switch between datasets. I tried to set the default dataset using the
default
key per the linked documentation, but Sanity doesn’t seem to respect it. Has anyone gotten this
default
key to work?
My
spaces
configuration in sanity.json is pasted in below. Notice I set the showcase-spr-22 as the default but when login into the Studio, the 2021-production dataset used by default.

"__experimental_spaces": [

{

"name": "showcase-spr-2022",

"title": "Spring 2022",

*"default": true*,

"api": {

"projectId": "myprojectid",

"dataset": "showcase-spr-2022"

}

},

{

"name": "showcase-win-2021",

"title": "Winter 2021",

"api": {

"projectId": "myprojectid",

"dataset": "showcase-win-2021"

}

},

{

"name": "2021-production",

"title": "Spring 2021",

"api": {

"projectId": "myprojectid",

"dataset": "2021-production"

}

},

{

"name": "production",

"title": "Spring 2020",

"api": {

"projectId": "myprojectid",

"dataset": "production"

}

},

{

"name": "development",

"title": "Development",

"api": {

"projectId": "myprojectid",

"dataset": "development"

}

}

]
AI Update

I can see you're working with the older __experimental_spaces feature. The good news is that this feature is now fully supported and documented as Workspaces in modern Sanity Studio (v3+). The __experimental_spaces configuration in sanity.json was the old Studio v2 approach, and it had some limitations - including the default key not always working reliably.

Here's what you need to know about migrating to the current Workspaces feature:

The Modern Approach: Workspaces

In Studio v3, workspaces are configured in your sanity.config.js (or .ts) file using the defineConfig helper. The configuration is much more robust and the default workspace behavior actually works as expected.

Here's how your configuration would look in the modern format:

import { defineConfig } from 'sanity'
import { deskTool } from 'sanity/desk'

export default defineConfig([
  {
    name: 'showcase-spr-2022',
    title: 'Spring 2022',
    projectId: 'myprojectid',
    dataset: 'showcase-spr-2022',
    plugins: [deskTool()],
    // Add your schema and other config
  },
  {
    name: 'showcase-win-2021',
    title: 'Winter 2021',
    projectId: 'myprojectid',
    dataset: 'showcase-win-2021',
    plugins: [deskTool()],
  },
  {
    name: '2021-production',
    title: 'Spring 2021',
    projectId: 'myprojectid',
    dataset: '2021-production',
    plugins: [deskTool()],
  },
  // ... other workspaces
])

The key difference: In the modern workspaces array, the first workspace in the array is automatically the default. So just put your showcase-spr-2022 workspace first, and it will be the default when users log in.

If You're Still on Studio v2

If you haven't migrated to Studio v3 yet and need to stick with __experimental_spaces, here are some workarounds:

1. Reorder your array: Move your preferred default to the first position. The Studio often falls back to using the first space when the default key doesn't work.

2. Use the query parameter: You can bookmark or share URLs with the ?space=showcase-spr-2022 parameter to force a specific space to load.

3. Consider migrating: Since the experimental spaces feature had known issues and is no longer the recommended approach, migrating to Studio v3 with proper Workspaces would give you more reliable behavior.

The default: true key in __experimental_spaces was indeed inconsistent in Studio v2, which is one reason the feature remained experimental. The modern Workspaces implementation resolves these issues with a cleaner, array-order-based approach to defaults.

Show original thread
8 replies
thanks
user U
:1. I do also have a the
api
key and it is set to the showcase-spr-2022 dataset2. the showcase-spr-2022 dataset is the first one in my ___experimental__spaces array, but no luck in having Sanity load it as the default

Can you check if the Studio’s core code is looking for the
default
key in the array of dataset objects?
can you check if the Studio core is looking for the
default
key in the array of dataset objects?
A quick test, I moved the default key in my test studio from my production to dev and it appears to have worked as intended.
{
  "root": true,
  "project": {
    "name": "jedilies"
  },
  "__experimental_spaces": [
    {
      "name": "prod",
      "title": "Production",
      
      "api": {
        "projectId": "bloop",
        "dataset": "production"
      }
    },
    {
      "name": "dev",
      "title": "Development",
      "default": true,
      "api": {
        "projectId": "bloop",
        "dataset": "development"
      }
    }
  ],
  "api": {
    "projectId": "blork",
    "dataset": "production"
  },

I retract my pondering on the array order unless possibly nothing is set as default.
I’m curious if you swap production with the spr22 dataset in your root api settings, does this change the priority?
hi
user U
, the
default
key does work as designed! I dug through our code and there was some hack that redirects to a hardcoded dataset and thus causing my confusion … thanks for looking into this!
No worries! I just rolled this into a friend’s project and was worried that I broke something myself!
Have a great weekend!

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?