Error implementing a singleton in Sanity config file
10 replies
Last updated: Feb 28, 2023
D
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, }, })
List items with same ID found (siteSettings)
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
https://www.sanity.io/docs/create-a-link-to-a-single-edit-page-in-your-main-document-type-list#fa1e82fd32be Here’s a link to the docs.
Dec 20, 2022, 12:45 PM
D
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
D
Tried both.
Dec 20, 2022, 4:58 PM
D
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
M
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.