Discussion about a reference warning in Sanity Studio and how to resolve it.
35 replies
Last updated: Aug 9, 2022
J
I just recently started seeing this in one of my posts, when did this get added and how do I see where it is referenced?
Aug 8, 2022, 5:17 PM
I believe this was added in the most recent release. I believe the only way to see these references listed is to use the Documents Pane plugin at the moment.
Aug 8, 2022, 5:31 PM
J
Hmm ok I’m just like I don’t remember “referencing” it so I'm curious
Aug 8, 2022, 5:33 PM
I do find it odd that the Studio warns you about the reference but doesn't provide the list of documents doing the referencing, though. It feels like clicking that link icon should surface that 🤷
Aug 8, 2022, 5:40 PM
J
The link icon just gives me that tooltip unfortunately. I don’t even know how a document is referenced
Aug 8, 2022, 5:42 PM
J
Yeah hopefully it can be updated soon
Aug 8, 2022, 7:17 PM
J
Just an FYI following that guide you linked
user M
I get a "Structure item is missing required typeproperty." when loading Sanity locally
Aug 8, 2022, 7:24 PM
J
I have
inside my
in the parts array
import S from "@sanity/desk-tool/structure-builder"; import DocumentsPane from "sanity-plugin-documents-pane"; S.view .component(DocumentsPane) .options({ query: `*[!(_id in path("drafts.**")) && references($id)]`, params: { id: `_id` }, useDraft: false, debug: true, }) .title("Incoming References");
src/deskStructure.jsand then in my
sanity.jsonI added
{ "name": "part:@sanity/desk-tool/structure", "path": "./src/deskStructure.js" }
Aug 8, 2022, 7:29 PM
Hmm, my implementation looks like it's working. Is it possible that you have something in your Structure that's missing a type?
Aug 8, 2022, 7:35 PM
J
Possibly 😅 I haven't used this before
Aug 8, 2022, 7:37 PM
J
I mean that is all I have in my
deskStructure.jsdo I need a
S.document()first?
Aug 8, 2022, 7:39 PM
Oh, I see! Yes, that particular piece of code would be attached to a custom desk structure item. If you don't have a custom desk structure, you could instead use a
getDefaultDocumentNodefunction to add the view. Like this:
import S from "@sanity/desk-tool/structure-builder"; import DocumentsPane from "sanity-plugin-documents-pane"; export const getDefaultDocumentNode = () => { return S.document().views([ S.view.form(), S.view .component(DocumentsPane) .options({ query: `*[!(_id in path("drafts.**")) && references($id)]`, params: { id: `_id` }, useDraft: false, debug: true, }) .title("Incoming References"); ]); };
Aug 8, 2022, 7:42 PM
J
So that gives me
Structure needs to export a function, an observable, a promise or a structure builder, got undefined
Aug 8, 2022, 7:44 PM
I thought we could get away without having to define any structure, but it looks like we need to also add:
That default export is just using the default methods for showing your document types.
import S from "@sanity/desk-tool/structure-builder"; import DocumentsPane from "sanity-plugin-documents-pane"; export const getDefaultDocumentNode = () => { return S.document().views([ S.view.form(), S.view .component(DocumentsPane) .options({ query: `*[!(_id in path("drafts.**")) && references($id)]`, params: { id: `_id` }, useDraft: false, debug: true, }) .title("Incoming References"); ]); }; export default () => S.list() .title('Content') .items( S.documentTypeListItems() )
Aug 8, 2022, 7:47 PM
J
So does this mean that it is somehow referencing itself?
Aug 8, 2022, 7:50 PM
J
Oh just kidding
No Documents found... but somehow saying it is a referenced document...
Aug 8, 2022, 7:51 PM
I wonder if a draft is referencing it? Can you try removing
!(_id in path('drafts.**))to check?
Aug 8, 2022, 7:53 PM
J
Well this is odd
Aug 8, 2022, 7:55 PM
Did you possibly have a reference field that was removed from your schema? If you inspect the JSON there may be a field that's not visible in the UI.
Aug 8, 2022, 7:56 PM
J
Nope never referenced that article in my Advertising document 😅
Aug 8, 2022, 7:56 PM
J
Even after publishing it says there is a reference... That
Unknown schema typepoints to the word
Redshirt Sportsin the Body
Aug 8, 2022, 7:58 PM
J
Nope it still shows up
Aug 8, 2022, 7:59 PM
J
Apparently I have an internal link to it somehow...
Aug 8, 2022, 8:01 PM
J
But I don't have an internalLink type anymore
Aug 8, 2022, 8:02 PM
Ah, it must have had that type previously, got added somehow, then the internal link type was removed. Since removing the schema types doesn't remove any data, the internal link still exists.
Aug 8, 2022, 8:03 PM
J
How do I remove it 😅
Aug 8, 2022, 8:05 PM
J
Because I don’t remember adding it
Aug 8, 2022, 8:05 PM
Honestly the easiest way would be to add the internal link schema back in then edit it in the Studio UI. otherwise you'd need to run a patch which is a lot of code to write just to remove a single block.
Aug 8, 2022, 8:07 PM
J
🥲 I don’t even remember having an internalLink at least in production. Gotta go see what I did locally 😅
Aug 8, 2022, 8:30 PM
J
I got it resolved
Aug 9, 2022, 12:37 AM
J
Not sure why I would have referenced an article on that page to begin with but thanks for the help!
Aug 9, 2022, 1:01 AM
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.