Issue with missing data in responses from the Sanity Client in Next.js 14 codebase.

8 replies
Last updated: Feb 14, 2024
Since yesterday/today, we at MR MARVIS are having some issues with the responses from the Sanity Client (in our Next.js 14 codebase). Randomly, data seems to be missing from the response.
See the attachment for instance. The left side works, and the highlighted information is present. On the right side (which was generated 5 seconds later by refreshing the page), the media information is missing.
AI Update

Based on the symptoms you're describing and the timing ("since yesterday/today"), this is almost certainly related to the recent API version 2025-02-19 change that Sanity deployed on February 24, 2025. This is a breaking change that switched the default perspective from raw to published.

What's Happening

The intermittent missing data you're seeing (especially with media/asset references) is likely because:

  1. The default perspective changed to published - Your queries are now only returning published documents by default, not drafts
  2. Asset references might be in draft state - If the media information or asset references haven't been published (or were saved as drafts), they won't appear in the published perspective
  3. The randomness is probably due to caching - The Live CDN has a ~10 minute cache with stale-while-revalidate, so you're seeing cached responses with the old raw perspective mixed with fresh responses using the new published perspective

Quick Fix

Update your Sanity client configuration to explicitly use the raw or previewDrafts perspective to restore the previous behavior:

import {createClient} from '@sanity/client'

const client = createClient({
  projectId: 'your-project-id',
  dataset: 'your-dataset',
  useCdn: true,
  apiVersion: '2024-01-01', // or your current version
  perspective: 'raw', // Add this to get both published and draft content
})

Or if you're using the Next.js integration, you can set it in your queries:

const data = await client.fetch(query, params, {
  perspective: 'raw'
})

Long-term Solution

You have two options:

  1. Keep using perspective: 'raw' if you need both draft and published content
  2. Ensure all content is properly published and switch to using perspective: 'published' (the new default)

More Details

The API version 2025-02-19 changelog explains this breaking change. The default perspective switch means queries now only return published documents unless you explicitly specify otherwise. This was done to support the new Content Releases feature, but it affects all queries made without an explicit perspective parameter.

The timing of "since yesterday" aligns perfectly with this deployment, and the intermittent nature is consistent with CDN cache behavior during the transition period. You can also check status.sanity.io for any ongoing incidents, though this appears to be a planned breaking change rather than an outage.

👋 Can you share more information about your build and how you’re querying this data?
Also, since it’s difficult to read that screen shot, can you paste just the expected output vs the output you get here? You can simplify it to just the missing information.
• useCdn true/false doesn't differ• Next.js 14 / Node 20 (also breaks on Node 18)
• Sanity client (
sanity@3.28.0
)
We've created a query URL, you can clearly see the randomness in responses if you refresh this page a couple of times


https://yb9xf4jc.api.sanity.io/v2022-03-07/data/query/production?query=*%5B_type+in+%5B%[…]A++++%7D%2C%0A++++%7D%0A++%7D%0A%7D&perspective=published
Every 5-10 refreshes we have the difference in response.
Thank you!
We were able to reproduce this and have found the cause. A change was rolled out to our backend that effected the way references were resolved. It has been reverted and you should no longer experience it. I apologize that you experienced it!
Thank you!

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?