Troubleshooting deploying new schemas in Sanity Studio for Next.js app

23 replies
Last updated: Jun 6, 2023
Good afternoon! I currently have sanity studio (v3) setup in my next.js application. How do I go about deploying new schemas so I can use the vision tool properly? I added the schemas and they are showing in the desk view, but I can't query them correctly in the vision desk... I noticed that when I went back to "sanity.io/manage " the studio did not have my recent schema changes, yet the localhost:3000/studio/desk does. What do I need to do to add schemas properly? Thanks!
AI Update

I can see the issue you're running into! When you're running Sanity Studio embedded in your Next.js app (at localhost:3000/studio), you're essentially running a local development version of the Studio. This is different from any hosted/deployed Studio you might have at manage.sanity.io.

The key thing to understand: Your schemas are defined in your code (in your Next.js project), and they work locally because your local Studio reads them directly from your codebase. The Vision tool should work perfectly fine with just your local schemas for basic querying - you don't actually need to "deploy" schemas to query them in Vision.

If Vision isn't showing your documents correctly, here are the most common issues:

  1. Dataset mismatch: In Vision, check the dropdown at the top to make sure you're querying the correct dataset (likely "production" or "development"). Your new documents might be in a different dataset than what Vision is currently pointing to.

  2. API version: Also in Vision's dropdown, verify you're using the correct API version. Try using the latest API version to ensure you're getting the most up-to-date behavior.

  3. Document creation: Make sure you've actually created documents with your new schema types in the Desk view. Just adding the schema doesn't create documents - you need to create actual content using those schemas first.

  4. Authentication/Perspective: Vision uses your authenticated session and can see drafts. Try querying with *[_type == "yourSchemaType"] to see all documents of that type.

Regarding manage.sanity.io:

The Manage interface at manage.sanity.io is for project administration (managing team members, datasets, API tokens, etc.). It's separate from your Studio. If you're running an embedded Studio in Next.js, you typically won't see schema changes reflected at manage.sanity.io because that's not where your Studio is hosted.

When you DO need to deploy schemas:

Schema deployment via sanity schema deploy is only necessary if you're using newer AI features like Agent Actions, AI Assist, or Canvas. For basic Vision querying in your local embedded Studio, it's not required.

However, if you want a hosted version of your Studio at yourproject.sanity.studio (which would show up in manage.sanity.io), you'd run sanity deploy - this builds and deploys your entire Studio to Sanity's hosting, including your schemas.

Try this first: In your Vision tool, make sure you're on the right dataset and try a simple query like *[_type == "yourNewSchemaType"] - that should show you if documents of that type exist. The issue is almost always dataset selection rather than schema deployment!

👋 You’ll have to redeploy your Next app to get any local changes to show up on your site.
Thanks for the help! I have my studio setup at localhost:3000/studio. When I go to that page the studio/desk looks correct and as it should.
But groq query doesn't seem to "query" the new schema fields as expected...
Can you share an example of a document you’ve created that doesn’t show up in in Vision? As well as the query you’re running?
Yes, one moment.
import { defineType, defineField } from "sanity";

export default defineType({
title: "community",
name: "Community",
type: "document",
fields: [
defineField({
name: "resource",
title: "Resource",
type: "string",
}),
defineField({
name: "description",
description: "Enter a short snippet for the resource...",
title: "Description",
type: "string",
}),
defineField({
name: "url",
description: "Enter a redirect url",
title: "Url",
type: "string",
}),
defineField({
name: "type",
title: "Type",
type: "array",
of: [{ type: "reference", to: { type: "resource-type" } }],
}),
],
});
import { defineType, defineField } from "sanity";
import { defineType, defineField } from "sanity";export default defineType({
  title: "community",
  name: "Community",
  type: "document",
  fields: [
    defineField({
      name: "resource",
      title: "Resource",
      type: "string",
    }),
    defineField({
      name: "description",
      description: "Enter a short snippet for the resource...",
      title: "Description",
      type: "string",
    }),
    defineField({
      name: "url",
      description: "Enter a redirect url",
      title: "Url",
      type: "string",
    }),
    defineField({
      name: "type",
      title: "Type",
      type: "array",
      of: [{ type: "reference", to: { type: "resource-type" } }],
    }),
  ],
});
*[_type == 'community']
Did you also create a community document in the Studio?
I did not, I created the schema, added it to the schema types and then it showed up in studio/desk.
If I search by types in the studio/desk, type community shows..
Got it. The backend is schemaless, so you won’t be able to query for that type until an actual document exists in your dataset.
okay. Could you please give me a bit of direction to make sure I create a document in the dataset correctly?
In the same way you create any document in the Studio, you’d open it in the desk and add data to it.
I do already have data in the community.
thank you for your help rd!
Ah weird! I misunderstood then. Did you maybe misspell something when you imported it into your
schema.js
?
import blockContent from "./blockContent";
import category from "./category";
import community from "./community";
import resource from "./resource";
import post from "./post";
import author from "./author";

export const schemaTypes = [
  post,
  author,
  category,
  community,
  blockContent,
  resource,
];
Doesn't look like it. Are there any cli commands I need to run for this to properly update the dataset for my projectId? Ive ran sanity build, sanity deploy...
No, any changes you make in the Studio get written to your dataset in real time, even if it’s a local Studio. Do you have mulltiple datasets? If so, is it possible that your Studio is using one dataset, but Vision is querying a different one?
I have a "Freeride blog" and a "production" dataset.
Thanks again rd. I deleted my sanity project, then created a new project with an empty schema, and once I got everything configured, it worked. Just wanted to let you know I got past our issue. Thanks for the support!

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?