Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Error implementing a singleton in Sanity config file

10 replies
Last updated: Feb 28, 2023
v3
— Errors trying to implement a singleton.I'm following this:
https://www.sanity.io/docs/set-up-structure-builder-to-override-the-default-list-view and have this as my
sanity.config.ts

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

const myStructure = (S: StructureBuilder) =>
  S.list()
    .title('Base')
    .items([
      S.listItem()
        .title('Site Settings')
        .child(S.document().schemaType('siteSettings').documentId('siteSettings')),
      ...S.documentTypeListItems(),
    ])

const mySchemaTypes = [
  {
    name: 'siteSettings',
    title: 'Site Settings',
    type: 'document',
    fields: [
      {
        name: 'title',
        title: 'Site Title',
        type: 'string',
      },
      {
        name: 'description',
        title: 'Site Description',
        type: 'text',
      },
    ],
  },
  {
    name: 'posts',
    type: 'document',
    title: 'Posts',
    fields: [
      {name: 'title', type: 'string', title: 'Title'},
      {name: 'slug', type: 'slug', title: 'Slug'},
      {name: 'content', type: 'array', title: 'Content', of: [{type: 'block'}]},
    ],
  },
]

export default defineConfig({
  name: 'default',
  title: 'sanity-11ty',

  projectId: import.meta.env.SANITY_STUDIO_PROJECT_ID,
  dataset: import.meta.env.SANITY_STUDIO_DATASET,

  plugins: [
    deskTool({
      structure: myStructure,
    }),
  ],

  schema: {
    types: mySchemaTypes,
  },
})
But get an error:
List items with same ID found (siteSettings)
What am I doing wrong?
Dec 20, 2022, 12:42 PM
You need to filter the
documentTypeListItems()
to remove the siteSettings document from appearing twice.

...S.documentTypeListItems().filter(listItem => !['siteSettings'].includes(listItem.getId()))
Dec 20, 2022, 12:44 PM
Thanks
user K
I saw that.However using that results in a different error:
Invalid link. Your link must contain a type.
Dec 20, 2022, 4:50 PM
I’ve used your schema and got it working on my end which is strange.
Dec 20, 2022, 4:53 PM
Have you tried restarting the dev server?
Dec 20, 2022, 4:54 PM
Or refresh the page.
Dec 20, 2022, 4:54 PM
Tried both.
Dec 20, 2022, 4:58 PM
user K
So I nuked the Sanity project. Upgraded everything. Created a new project from scratch and used the same Schema and the problem has gone away. No idea what happened. Thanks for your help though.
Dec 20, 2022, 5:43 PM
That’s really odd. Well, glad it’s working now! 😆
Dec 20, 2022, 6:02 PM
the way I solved this same issue is simply by going back to the http://localhost:3333
Feb 28, 2023, 11:58 AM

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?