Sanity Studio: "Loading document..." indefinitely with custom structure builder

8 replies
Last updated: Dec 24, 2021
I ran into an interesting issue. A studio setup that worked fine so far has stopped working.ProductPages are collected by type via the structure builder like so:


S.listItem()
  .title("Product Pages")
  .id("productPages")
  .icon(Icon)
  .child(
    S.documentTypeList("productPage")
      .title("Product Pages")
      .menuItems(S.documentTypeList("productPage").getMenuItems())
      .filter("_type == $type")
      .params({ type: "productPage" })
      .child((documentId) =>
        S.document()
          .documentId(documentId)
          .views(Views({ type: "productPage" }))
      )
)
As mentioned this worked fine so far, but now clicking on one of the items results in an indefinite "Loading document..."

If I reenable collecting all the entries via


S.list()
    .title("Content")
    .items([
      ...S.documentTypeListItems(),
    ])
it again loads the document successfully.

Downgrading / upgrading seems to have not resolved the issue. I also logged out and in again via the CLI.
The dev tools don't provide any useful output besides a structure warning:

Structure warning: document type (
schemaType
) will be required for document nodes in the near future! At:
root > productPages > 82661311-f27a-44f1-88b0-bf756a78a28b"
AI Update

Based on the warning message you're seeing, the issue is clear: Sanity now requires the schemaType parameter when using S.document() in the Structure Builder, and this is becoming a mandatory requirement.

The warning tells you exactly what's missing:

Structure warning: document type (schemaType) will be required for document nodes in the near future!

Your current code creates document nodes without specifying the schema type:

.child((documentId) =>
  S.document()
    .documentId(documentId)
    .views(Views({ type: "productPage" }))
)

The fix is simple β€” add .schemaType('productPage') to your document node:

S.listItem()
  .title("Product Pages")
  .id("productPages")
  .icon(Icon)
  .child(
    S.documentTypeList("productPage")
      .title("Product Pages")
      .menuItems(S.documentTypeList("productPage").getMenuItems())
      .filter("_type == $type")
      .params({ type: "productPage" })
      .child((documentId) =>
        S.document()
          .documentId(documentId)
          .schemaType('productPage')  // <-- Add this line
          .views(Views({ type: "productPage" }))
      )
  )

The reason it works when you use S.documentTypeListItems() is because that convenience method automatically handles the schema type association for you. When you build custom structures with S.document(), you need to explicitly specify it.

This change is part of Sanity's move toward more explicit structure definitions, which helps improve type safety and makes the structure configuration more predictable. The Structure Builder documentation shows examples using .schemaType() for document nodes.

The "indefinite loading" happens because without the schema type, Studio can't properly resolve which document schema to use for rendering the document, causing the loading state to hang.

Show original thread
8 replies
Hi
user L
- happy holidays! In your custom views, could you try adding a
schemaType
? e.g.
.schemaType('productPage')
This indeed worked:
.child((documentId) =>
        S.document()
          .documentId(documentId)
          .views(Views({ type: "productPage" }))
          .schemaType("productPage")
      )
This indeed worked:
.child((documentId) =>
        S.document()
          .documentId(documentId)
          .views(Views({ type: "productPage" }))
          .schemaType("productPage")
      )
(
views(Views({ type: "productPage" }))
was part of the code earlier as well)
Thank you for the incredibly fast help
user M
! Much appreciated πŸ™‚
If this is reproducible across different setups, that could mean, that the warning message should possibly be adapted?
At the moment it doesn't suggest anything being broken and feels more like a deprecation warning.
Glad to hear it's working! And I think you're spot on: the warning suggests it shouldn't break (yet). We'll look into fixing this. Thanks for the feedback πŸ™‚
Thanks again for helping and enjoy the holidays Peter! πŸ™‚ πŸŽ„

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?