πŸ‘€ See Sanity in action: Watch product demo now β†’

When Should the `.documentId` Parameter be Added to the Desk Structure Schema?

7 replies
Last updated: Apr 13, 2022
Hey everyone! I have a question about how to properly build my
desk-structure
schema.. I am in the process of updating my Sanity Studio for an open-source project to make it more organized and and I have somewhat referencing the https://github.com/sanity-io/sanity-shopify-studio
desk
structure..
Anyway, my question is when should I add in the
.documentId
parameter? So far my desk structure schema works, but I have actually always been confused about when to actually use this (even though I've been using Sanity for a couple years now lol). For instance I have a
home.js
file that is fed into my
desk-structure.js
file:

home.js

 import S from '@sanity/desk-tool/structure-builder'

// Icons
import {
  House,
} from 'phosphor-react'

export const home = S.listItem()
  .title('Home')
  .icon(House)
  .child(
    S.document()
    .title('Home Page')
    .schemaType('landingPage')
  )

desk-structure.js

import S from '@sanity/desk-tool/structure-builder'

import { home } from './desk/home'
import { pages } from './desk/pages'
import { articles } from './desk/articles'
import { authors } from './desk/authors'
import { settings } from './desk/settings'

// Doc types
const hiddenDocTypes = (listItem) =>
  ![
    'landingPage',
    'page',
    'article',
    'author',
    'headerSettings',
    'footerSettings',
    'seoSettings',
    'promoSettings',
    'cookieSettings'
  ].includes(listItem.getId())

export default () =>
  S.list()
    .title('Content')
    .items([
      home,
      pages,
      articles,
      S.divider(),
      authors,
      S.divider(),
      settings,

      // Filter out docs already defined above
      ...S.documentTypeListItems().filter(hiddenDocTypes)
    ])
Meanwhile my
settings.js
contains the
.documentId
parameter (and I dont really know why I should have it in here and not in my
home.js
as well?):
import S from '@sanity/desk-tool/structure-builder'

// Icons
import {
  Sliders,
  NavigationArrow,
  List,
  Globe,
  FlagBanner,
  Cookie
} from 'phosphor-react'

export const settings = S.listItem()
  .title('Settings')
  .icon(Sliders)
  .child(
    S.list()
      .title('Settings')
      .items([
        S.listItem()
          .title('Header')
          .icon(NavigationArrow)
          .child(
            S.editor()
              .schemaType('headerSettings')
              .documentId('headerSettings')
          ),
...etc.
Any clarification on this would be really helpful. I have tried reading the docs to find the answer, but I am still confused on this aspect of Sanity.
Apr 13, 2022, 7:15 PM
Hey
user M
thanks for getting back to me! Actually my
settings.js
is made up of many document items.. (I added in the ...etc. to indicate this, but I just didn't want to post a long code bracket lol).
Yes the only single document I have is my
landingPage
which does not have a
.documentId
. Here is the weird thing though.. When I add in a
.documentId
to my
home.js
my page builder seems to break.. I attached a short screen grab of this.
Here is my schema now: (which breaks my page-builder)

import S from '@sanity/desk-tool/structure-builder'

// Icons
import {
  House,
} from 'phosphor-react'

export const home = S.listItem()
  .title('Home')
  .icon(House)
  .child(
    S.document()
    .title('Home Page')
    .schemaType('landingPage')
    .documentId('landingPage')
  )
It seems it works better not using
.documentId
Apr 13, 2022, 7:52 PM
yeah idk what is going on lol.. After an hour messing around with it adding in
.documentId
breaks my page builder schema lol.. I mean it working though (and also works on live) so I guess its okay? I am just not sure whats going on lol
Apr 13, 2022, 9:48 PM
Ah, so the Studio doesn't break, but your frontend stops responding to the changes. I'm guessing that the singleton you're editing before adding in the document ID is a different document, maybe? How are you querying for it?
Apr 13, 2022, 9:52 PM
Yeah thats exactly whats going on! Hmm no I am editing the correct singleton.. Let me share the repo. This is for my open-source Gridsome/Shopify project using Sanity: https://github.com/rylanharper/BELRAD I am just trying to touch up the studio to make it more accessible.
The issue is with the
home.js
schema here . And I am querying the data in my
Index.vue
(using Graphql) here with a content-section builder using the
_type
from the Sanity schema found here . Lol again the website it working on my development sever and on live so nothing is technically wrong.. Its just that it my
home.js
desk schema seems to break when I add in a
documentId
which is really weird.
Apr 13, 2022, 10:16 PM
Hmm okay so I have been messing around and there is definitely something wrong with my landing page schema.. I changed the
landingPage
document to
homePage
(and also changed the name within my
schema.js
and
desk-structure.js
) and now I get the following message
This document is of type landingPage and cannot be edited as homePage.
However, upon inspecting the document the id is
homePage
but the _type is
landingPage
.. I just have no clue whats going on 😞
Apr 13, 2022, 11:14 PM
user M
I FIGURED IT OUT!! Lol this all was a really dumb mistake πŸ€¦β€β™‚οΈ.. It turns out that I never actually deleted the original document I was editing.. So even back when I was editing my
landingPage
(now homePage) and added in the
.documentId
to the schema I was actually editing the old document. To fix it I just had to go to the bottom and delete the document and then create a new one.. Now my page-builder is working. I am so sorry to waste your time with this.. It was just a dumb mistake/error on my end
Apr 13, 2022, 11:36 PM
No worries! Very happy to be your rubber duck as you worked it out :rubberduck: !
Apr 13, 2022, 11:50 PM

Sanity.io – build remarkable experiences at scale

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