Error encountered when duplicating a document in Slack thread.

8 replies
Last updated: Sep 11, 2023
Hi all,
I’m trying to duplicate a document and it gives me the following error:


STRUCTURE PATH
housing -> article -> c890dbaa-a78f-4001-9514-926e850deb51 -> editor
ERROR
document type (`schemaType`) is required for document nodes
Any clue what’s going on? Creating new ones work fine, but crashes on duplicate.
Aug 21, 2023, 10:06 AM
If you create a new document and duplicate that, do you still see this issue? If this is only happening for older documents, I wonder if the schema was changed leading to some stray fields in the document.
Aug 21, 2023, 3:12 PM
it happens on new documents
Aug 21, 2023, 3:12 PM
Documents are being created through a custom menuItem:

.menuItems([
          S.menuItem()
            .title('Create')
            .icon(ComposeIcon)
            .intent({ type: 'create', params: { type: schemaTypeName, template: `${schemaTypeName}-${language}` } }),
          //Crashes unless canHandleIntent is present (<https://github.com/sanity-io/sanity/issues/3140>)
        ])
        .canHandleIntent((intent, { type }) => ['create', 'edit'].includes(intent) && type === schemaTypeName),
Aug 21, 2023, 3:14 PM
which works fine. But duplication fails with the above error.
Aug 21, 2023, 3:23 PM
Can you try the following:1. Create a document of this type outside of the custom menuItem using the same template
2. Duplicate this document - does it throw the same error?
3. If it does not throw any error, inspect the document and compare that with the one created from the menuItem and see if there are any differences that stand out

Aug 21, 2023, 3:42 PM
Thanks. I made it work by explicitly providing the schemaType to my documentList:

S.documentList()
        .title(title)
        .schemaType(schemaTypeName)
Aug 22, 2023, 8:45 AM
Hi, I saw that adding this introduced another error:
If I add schemaType on the documentList, the duplication error is resolved. However, in that case, when I click create, it doesnt immediately create a new document using the provided initial template, but rather give me a list with all the different initial templates I have for that schema type:
Sep 11, 2023, 12:11 PM
To sum up:
• If I add .schemaType(type) to the listItem(), then the Creating works as expected. Meaning it immediately creates a new doc with the template.
• If I add .schemaType(type) to the documentList(), then the duplication error is resolved, but introduces the list above on creation.
Sep 11, 2023, 12:14 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?