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

Discussion on setting default dataset in Sanity Spaces feature

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"

}

}

]
Apr 15, 2022, 11:17 PM
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?
Apr 15, 2022, 11:33 PM
can you check if the Studio core is looking for the
default
key in the array of dataset objects?
Apr 15, 2022, 11:34 PM
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"
  },

Apr 15, 2022, 11:39 PM
I retract my pondering on the array order unless possibly nothing is set as default.
Apr 15, 2022, 11:40 PM
I’m curious if you swap production with the spr22 dataset in your root api settings, does this change the priority?
Apr 15, 2022, 11:54 PM
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!
Apr 15, 2022, 11:58 PM
No worries! I just rolled this into a friend’s project and was worried that I broke something myself!
Apr 15, 2022, 11:59 PM
Have a great weekend!
Apr 15, 2022, 11:59 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?