Comments (10)
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.
Closing due to inactivity
from sanity.
@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.
@skyatlinear do you happen to have any customizations in this studio? For example, any custom document actions?
from sanity.
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.
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.
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 title
s 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.
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.
Should be solved with the above tips!
from sanity.
That works, thanks!
from sanity.
Related Issues (20)
- Weak references strengthened on publish
- Schedule date picker - month shows the minutes value! HOT 1
- Updates cause error on slow network - getAttribute only applies to plain objects
- Sanity 3.52.2 RollupError: "FieldPresenceWithOverlay" is not exported by "node_modules/sanity/lib/index.mjs" for sanity-plugin-icon-manager HOT 1
- Referenced document won't open in group tab. HOT 6
- Seemingly unpredictable syntax errors when running codegen.
- "Review changes" pane is not showing diffs
- [Docs] Vision Plugin - Example in docs need update, since Desk is now Structure
- PortableText "inline blocks" style bug HOT 1
- Sanity studio does not enable the Publish button when treeArrayEditing is active HOT 2
- Refresh document locations on editing fields
- [Typegen error] - Undefined namespace: geo HOT 2
- Image field causes layout shifts when opening a document
- Type error in Sanity Client index.d.ts:1330:5 while deploying with vercel HOT 6
- Radio button in PortableText annotation causes popups to disappear in Safari
- Can't open referenced items in grouped views HOT 2
- Presentation tool crashes with Contributor role
- Unable to connect to visual editing in Sanity with Nuxt on Vercel
- Querying images from the Content Lake returns the wrong type HOT 5
- Certain projections in the Structure Builder's filter() method cause certain updates to not happen on document lists HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sanity.