Unlock seamless workflows and faster delivery with our latest releases – get the details

Discussion about a reference warning in Sanity Studio and how to resolve it.

35 replies
Last updated: Aug 9, 2022
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
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
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
Yeah, I meant that it feels like we've made the UI a little bit confusing here.
Aug 8, 2022, 5:43 PM
Yeah hopefully it can be updated soon
Aug 8, 2022, 7:17 PM
Just an FYI following that guide you linked
user M
I get a "Structure item is missing required
type
property." when loading Sanity locally
Aug 8, 2022, 7:24 PM
I have
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");
inside my
src/deskStructure.js
and then in my
sanity.json
I added
{
      "name": "part:@sanity/desk-tool/structure",
      "path": "./src/deskStructure.js"
    }
in the parts array
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
Possibly 😅 I haven't used this before
Aug 8, 2022, 7:37 PM
Feel free to copy/paste your structure if you need a second pair of eyes!
Aug 8, 2022, 7:38 PM
I mean that is all I have in my
deskStructure.js
do 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
getDefaultDocumentNode
function 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
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:
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()
    )
That default export is just using the default methods for showing your document types.
Aug 8, 2022, 7:47 PM
So does this mean that it is somehow referencing itself?
Aug 8, 2022, 7:50 PM
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
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
Or possibly you need to publish that page to remove the reference.
Aug 8, 2022, 7:56 PM
Nope never referenced that article in my Advertising document 😅
Aug 8, 2022, 7:56 PM
I think that Unknown schema type bit might contain the reference.
Aug 8, 2022, 7:57 PM
Even after publishing it says there is a reference... That
Unknown schema type
points to the word
Redshirt Sports
in the Body
Aug 8, 2022, 7:58 PM
Weird. Does publishing it remove the reference warning in the other document?
Aug 8, 2022, 7:58 PM
Nope it still shows up
Aug 8, 2022, 7:59 PM
Apparently I have an internal link to it somehow...
Aug 8, 2022, 8:01 PM
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
How do I remove it 😅
Aug 8, 2022, 8:05 PM
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
🥲 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
I got it resolved
Aug 9, 2022, 12:37 AM
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.

Was this answer helpful?