Understanding and modifying an existing Sanity project without documentation

10 replies
Last updated: Feb 18, 2022
hey guys, thank you very much for setting up this community! I've been able to find your guides for getting started, but none for getting my bearings on an existing Sanity project- could you point me to any helpful resources / give me any useful tips for this situation? It's a pretty simple site, but the site owners don't think they can put me in touch with the original dev. If it helps, I think I just need to create a new block type that'll show up in this dropdown, but not sure where to start on that. 2nd picture is the UI before I open the dropdown.TYIA!
AI Update

Welcome to the community! Great question - diving into an existing Sanity project without access to the original developer is definitely doable. Let me help you get oriented and solve your specific issue with adding a new block type.

Getting Your Bearings on an Existing Project

Here's a practical roadmap for exploring an unfamiliar Sanity project:

1. Start with sanity.config.ts/js - This is your project's main configuration file at the root. It tells you:

  • Your project ID and dataset name
  • Which plugins are installed
  • How schemas are registered
  • Any custom Studio configurations

2. Find the schema files - Look for a schemas or schemaTypes folder. This is your blueprint:

  • Files that export schema definitions (using defineType or defineField)
  • An index.ts/js that usually imports and combines all schema types
  • Document types (top-level content) vs object types (reusable components)

3. Identify the field you're working with - Since you're looking at a dropdown in a rich text editor, search your schemas for fields with type: 'array' that contain {type: 'block'} - this is Portable Text.

4. Check the Studio structure - Look at how content types are organized in the Studio UI to understand the project's content model.

Adding a Custom Block Type to That Dropdown

Based on your screenshot showing a dropdown in the Portable Text editor, here's exactly how to add a new block type:

Step 1: Create your custom block schema

Create a new file in your schemas folder (or add to an existing one):

import {defineType, defineField} from 'sanity'

export const myCustomBlock = defineType({
  name: 'myCustomBlock',
  type: 'object',
  title: 'My Custom Block',
  fields: [
    defineField({
      name: 'content',
      type: 'string',
      title: 'Content',
    }),
    // Add whatever fields you need
  ]
})

Step 2: Register it in your schema

Add your new block type to your schema index file where all types are exported (usually schemas/index.ts).

Step 3: Add it to the Portable Text field

Find the schema file that contains the field with that dropdown (likely the main content field for a document type). Look for something like this:

defineField({
  name: 'body', // or 'content', etc.
  type: 'array',
  of: [
    {type: 'block'}, // This is the standard text
    {type: 'image'}, // Existing custom blocks
    {type: 'myCustomBlock'}, // Add your new block here!
  ]
})

Once you save and restart your Studio (if running locally with sanity dev), your new block type should appear in that dropdown!

Important Distinction: Styles vs Block Types

Looking at your dropdown, I need to clarify something important:

  • Block Types (what I described above) are for inserting non-text content like images, videos, or custom components between paragraphs
  • Styles are for text formatting options like "Heading 2" or "Quote" that appear in the style dropdown

If you're trying to add a text style (like a new heading level), you'd configure it differently:

defineField({
  name: 'body',
  type: 'array',
  of: [
    {
      type: 'block',
      styles: [
        {title: 'Normal', value: 'normal'},
        {title: 'Heading 2', value: 'h2'},
        {title: 'My Custom Style', value: 'myStyle'}, // Add here
      ]
    }
  ]
})

Tips for Working Without the Original Dev

  • Be careful with schema changes - Modifying existing schemas can affect existing content
  • Test in a development dataset if possible
  • Check for any documentation - Look for README files or comments in the code
  • Use Studio's built-in tools - The Vision plugin (if installed) lets you query your data with GROQ to understand the structure

If you share more details about what kind of block you're trying to add (is it for inserting custom content, or formatting text?), I can give you more specific guidance!

Show original thread
10 replies
yes!
I used sanity login & sanity init to add the project to a local folder. Only one project & dataset were available. My first instinct was to search all files for the names of the existing blocks, but got 0 results for that πŸ˜•
You unfortunately can't download the code for an existing Studio using the Sanity CLI. You'd have to clone the repo from something like Github. Do you have access to that?
oh, got it. Let me check
Is there any place in the Studio settings or Sanity Project settings that lists / might list the repo? Definitely haven't gotten anything directly from the client, besides Sanity read-write access
No, it's a completely separate piece. If the Studio has been deployed, though, you can try to recover the schema using this method. You can then just add them to an empty Studio, change the project ID in
sanity.json
to the correct one, and go from there!
I'll go ahead and do that, thank you!!
You're welcome! Let us know if you're still having trouble!
Hi again Racheal! They gave me access to the repository and that's helped a lot, thank you very much! I have an unrelated question that I'll put back in the main thread πŸ™‚
Hi again Racheal! They gave me access to the repository and that's helped a lot, thank you very much! I have an unrelated question that I'll put back in the main thread πŸ™‚

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?