GithubHelp home page GithubHelp logo

Comments (10)

bjoerge avatar bjoerge commented on September 22, 2024

Hi @pacocoursey – sorry you're running into this.

I'm not able to reproduce this, unfortunately. Any chance you could provide more details about the steps you took to get this error? Or provide a minimal and runnable repro project?

from sanity.

bjoerge avatar bjoerge commented on September 22, 2024

Closing due to inactivity

from sanity.

skyatlinear avatar skyatlinear commented on September 22, 2024

@bjoerge Sky here. This activity is happening for me and paco reached out on my behalf. I'm uploading how I got to the page here.

CleanShot.2024-05-29.at.13.09.15.mp4

from sanity.

bjoerge avatar bjoerge commented on September 22, 2024

@skyatlinear do you happen to have any customizations in this studio? For example, any custom document actions?

from sanity.

skyatlinear avatar skyatlinear commented on September 22, 2024

I just edited something and didn't see anything similar, but I'm not confident that's the best way to check. Is there a better way to confirm?

from sanity.

juice49 avatar juice49 commented on September 22, 2024

Hi @skyatlinear. Customisations would be made in your Studio configuration file, which is usually named sanity.config.ts. It'd be best to check by looking in there. Do you have access to your Studio project's source code?

from sanity.

pacocoursey avatar pacocoursey commented on September 22, 2024

Hey, sorry for the delay here.

We use a custom deskStructure.ts to organize the sidebar in places where we use singleton documents (i.e. only one of these document types should exist at once). In this case, we customize the link to our partners list using this logic:

async function findSingletonDocument(type) {
  const id = await client.fetch(`*[_type == "${type}"][0]._id`);
  return S.document().documentId(id).schemaType(type);
}

...
S.listItem()
  .title("Partners")
  .child(
    S.list()
      .title("Partners Documents")
      .items([
        S.listItem()
          .title("Partners Index")
          .child(async () => {
            return await findSingletonDocument("partners.page");
          }),
        S.divider(),
        S.listItem()
          .title("Partners List")
          .child(async () => {
            return await findSingletonDocument("partners.list");
          }),
      ])
  )
...

This leads to a studio URL like /structure/partners;partnersList (I guess the titles are slugified to generate that?) which then crashes the studio.

If we use a direct URL to the document like /structure/partners.list;e535e3e1-7b30-492c-8c9e-f0fc83e03234 then the studio does not crash.

from sanity.

runeb avatar runeb commented on September 22, 2024

Thanks for getting back to us with code, @pacocoursey

I feel confident that what is happening here is that your query finds a draft document, and the id passed to
S.document().documentId(id).schemaType(type); contains the drafts. prefix. Sorry you are affected by this! We should handle this more gracefully behind the scenes.

This change should fix it

async function findSingletonDocument(type) {
  const id = await client.fetch(`*[_type == "${type}"][0]._id`);
  const cleanId = id.startsWith('drafts.') ? id.slice(7) : id; // Remove 'drafts.' prefix if present
  return ;
}

Usually singleton documents utilize manually chosen ids since there should only exist one document per type. You can then pick a nice readable one and use it like this:

S.listItem()
  .title("Partners")
  .child(
    S.list()
      .title("Partners Documents")
      .items([
        S.listItem()
          .title("Partners Index")
          .child(
            S.document().documentId('partners-page').schemaType('partners.page')
          ),
        S.divider(),
        S.listItem()
          .title("Partners List")
          .child(
            S.document().documentId('partners-list').schemaType('partners.list')
          ),
      ])
  )

Then you also don't need to make a query here which should speed up your Structure Tool.

The first time you navigate to these documents they won't exist, so you could use something like the sanity documents create cli command to easily bootstrap it if you have existing content you want to get it started with.

from sanity.

runeb avatar runeb commented on September 22, 2024

Should be solved with the above tips!

from sanity.

pacocoursey avatar pacocoursey commented on September 22, 2024

That works, thanks!

from sanity.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.