Staging environment not using correct dataset despite configuration

13 replies
Last updated: Jul 26, 2022
I’m running into an issue where my staging environment isn’t using the content from our “staging” dataset, despite being configured to do so:
// netlify.toml

[[redirects]]
  from = "/*"
  to = "/"
  status = 200

[context.branch-deploy]
  environment = { GRIDSOME_SANITY_DATASET = 'staging' }
  NODE_ENV = "development"

[context.staging]
  environment = { GRIDSOME_SANITY_DATASET = 'staging' }
  NODE_ENV = "development"

// sanity.json
...
  "env": {
    "development": {
      "api": {
        "dataset": "staging"
      }
    }
  },
  "__experimental_spaces": [
    {
      "name": "production",
      "title": "Production",
      "default": true,
      "api": {
        "projectId": "xxxxxxx",
        "dataset": "production"
      }
    },
    {
      "name": "staging",
      "title": "Staging",
      "api": {
        "projectId": "xxxxxxx",
        "dataset": "staging"
      }
    }
  ],
...
Jul 22, 2022, 4:08 PM
I’ve gone over the configuration with a fine-toothed comb and have a number of other sites running the same config, but for some reason this one insists on using the production dataset.
Jul 22, 2022, 4:08 PM
The deploy logs in Netlify are even indicating that the staging dataset is being used!:
Jul 22, 2022, 4:09 PM
7:16:19 AM: $ npm run build-web
7:16:19 AM: > sanity-gridsome@1.0.4 build-web /opt/build/repo
7:16:19 AM: > lerna bootstrap && (cd studio && SANITY_AUTH_TOKEN=$SANITY_DEPLOY_STUDIO_TOKEN npm run graphql-deploy) && (cd web && npm run build)
7:16:19 AM: lerna notice cli v3.22.1
7:16:19 AM: lerna info ci enabled
7:16:19 AM: lerna info Bootstrapping 2 packages
7:16:19 AM: lerna info Installing external dependencies
7:16:35 AM: lerna info Symlinking packages and binaries
7:16:35 AM: lerna success Bootstrapped 2 packages
7:16:35 AM: > sanity-gridsome-studio@1.0.5 graphql-deploy /opt/build/repo/studio
7:16:35 AM: > sanity graphql deploy --playground
7:16:36 AM: Dataset: staging
7:16:36 AM: Tag: default
7:16:37 AM: Browserslist: caniuse-lite is outdated. Please run:
7:16:37 AM:   npx browserslist@latest --update-db
7:16:37 AM:   Why you should do it regularly: <https://github.com/browserslist/browserslist#browsers-data-updating>
7:16:40 AM: GraphQL API deployed to:
7:16:40 AM: <https://xxxxxxxx.api.sanity.io/v1/graphql/staging/default>
Jul 22, 2022, 4:10 PM
Anyone have any clue what might be happening?
Jul 22, 2022, 4:10 PM
Happy to provide more info if necessary!
Jul 22, 2022, 4:11 PM
Hey
user Q
! Just as a shot in the dark, does it make a difference if you move staging to the first index in your experimental spaces array?
Jul 22, 2022, 4:14 PM
Worth a shot!
Jul 22, 2022, 4:15 PM
Sadly that doesn’t seem to have done it
Jul 22, 2022, 4:19 PM
Copy in the back-end:
Jul 22, 2022, 4:20 PM
Copy on the front-end:
Jul 22, 2022, 4:20 PM
The only difference in the config is that I’m not using the Vision plugin 🤷‍♂️
Jul 22, 2022, 4:20 PM
If anyone stumbles upon this, turns out I had my config in the wrong netlify.toml file. The project is set up as a monorepo with one netlify.toml file in the studio folder and one in the root. This was the relevant line I was ignoring in the deploy logs:
Jul 26, 2022, 2:46 PM
5:24:48 PM: ❯ Config file
5:24:48 PM:   No config file was defined: using default values.
Jul 26, 2022, 2:47 PM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the 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?