๐Ÿ”ฎ Sanity Create is here. Writing is reinvented. Try now, no developer setup

Issue with desk structure previews not working on views with only one child

5 replies
Last updated: Feb 18, 2022
Using the desk structure previews (the split pane), how come the preview works in views that have multiple children, but doesn't work on views that only have one child?
Here's a screenshot of the preview not working on a view with only one document:

https://www.dropbox.com/s/bxnnnriuoiil3tg/Screenshot%202022-02-18%20at%2018.43.14.png?dl=0
And it working on a view with multiple documents:

https://www.dropbox.com/s/8l1e2clpj5sc9k6/Screenshot%202022-02-18%20at%2018.44.55.png?dl=0
I'll share my code inside this thread
Feb 18, 2022, 6:45 PM
import S from "@sanity/desk-tool/structure-builder";
import {
  GiHouse as HomepageIcon,
  GiScrollQuill as PageIcon,
  GiNewspaper as BlogIcon,
  GiMining as ServiceIcon,
  GiPaintRoller as ProjectIcon,
} from "react-icons/gi";
import Iframe from "sanity-plugin-iframe-pane";

import resolveProductionUrl from "./resolveProductionUrl";

// ---

export const getDefaultDocumentNode = () =>
  S.document().views([
    S.view.form(),
    S.view
      .component(Iframe)
      .options({
        url: (doc) => resolveProductionUrl(doc),
      })
      .title("Preview"),
  ]);

// ---

export default function deskStructure() {
  return S.list()
    .title("Content Manager")
    .items([
      S.listItem()
        .title("Homepage")
        .icon(HomepageIcon)
        .child(
          S.document()
            .schemaType("homepage")
            .documentId("defaultHomepage")
            .title("Homepage")
        ),
      S.listItem()
        .title("Pages")
        .icon(PageIcon)
        .child(() => S.documentTypeList("page")),
      S.listItem()
        .title("Blog Posts")
        .icon(BlogIcon)
        .child(() => S.documentTypeList("blogPost")),
      S.listItem()
        .title("Projects")
        .icon(ProjectIcon)
        .child(() => S.documentTypeList("project")),
      S.listItem()
        .title("Services")
        .icon(ServiceIcon)
        .child(() => S.documentTypeList("service")),
    ]);
}
Feb 18, 2022, 6:45 PM
Yeah that did it User, thanks. I don't fully understand what I'm doing with some of these things ๐Ÿ˜„
Feb 18, 2022, 7:59 PM
You saved me a rapping on the knuckles from the client "why isn't the preview working" haha
Feb 18, 2022, 8:00 PM
Haha, yeah, Structure Builder is super confusing to work with!
Feb 18, 2022, 8:03 PM
Really powerful though, the clients all love it when I can get it to behave
Feb 18, 2022, 8:03 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?