Old V2 project internal links suddenly stopped working overnight

4 replies
Last updated: Sep 27, 2023
Ello! I have an old v2 project, suddenly my internal links stopped working, like over night. Has anyone encountered this before? Havent touched the project in months so its a bit weird. I will stick some more info in thread.
AI Update

This sounds like you've been hit by a recent breaking change in Sanity's API! On February 24, 2025, Sanity released API version 2025-02-19 which changed the default perspective from raw to published.

This is likely why your internal links stopped working overnight - if your references point to draft documents or you're querying for linked content, the API is now only returning published documents by default instead of all documents (drafts + published).

Quick fix:

You need to explicitly set the perspective parameter in your queries. Depending on how you're querying:

For GROQ queries:

const query = '*[_type == "post"]'
const params = { perspective: 'raw' } // or 'previewDrafts'
const data = await client.fetch(query, params)

For client configuration:

const client = sanityClient({
  // ... other config
  perspective: 'raw', // Add this to maintain previous behavior
  useCdn: false // You'll want CDN off for draft content
})

The raw perspective gives you the old behavior (both drafts and published docs), while previewDrafts gives you drafts with published as fallback.

If you're using GraphQL, you'll need to add the perspective parameter there as well.

This change happened automatically when Sanity updated their API version, even if you haven't touched your project. The good news is it's a straightforward fix once you know what's happening!

Show original thread
4 replies
internalLink: (props: any) => {
      console.log('props : ', props);
      return (
        <ArticleLink type={ArticleLinkType.Internal} href={'#'}>
          {props.node.text}
        </ArticleLink>
      );
    },
log of props:

props :  {
  node: {
    _key: '835e9c573f05',
    reference: {
      _ref: '18124180-6ce3-4b31-b12e-bf9ad911bf26',
      _type: 'reference'
    },
    _type: 'internalLink',
    text: 'interal'
  },
Query

groq`*[_type == "article" && content.slug.current == $slug][0]{
          ...,
          content{
            ...,
            "media": ${groqFormatMedia('media')},
            body[] {
              ...,
              ...select(
                @._type == "fileLink" => @ {
                  ...,
                  file{
                    ...,
                    "url": asset->url,
                  },
                },
              ),
            }
          },
By ‘stopped working’ do you mean you get an error or does it not render at all?
Sorry, it applied its own slug to the href. A new query fixed it.
Thanks for updating us!

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?