Images not displaying in Portable Text Editor, showing inline elements instead

5 replies
Last updated: Aug 18, 2021
Hey fine folks! Quick question - does anyone else have images in their SANITY studio look like this? I remember at one time I used to be able to see the actual image in the portable text editor but now I get these less than ideal inline elements. Does it maybe have something to do with needing to hoist the GraphQL schema? Here is what my image schema looks like in SANITY, which is then used inside the blockContent type.

export default {
  name: "figure",
  title: "Image",
  type: "image",
  options: {
    hotspot: true,
  },
  fields: [
    {
      title: "Caption",
      name: "caption",
      description: "Leave blank if you do not want a caption",
      type: "string",
      options: {
        isHighlighted: true,
      },
    },
    {
      name: "alt",
      type: "string",
      title: "Alternative text",
      validation: (Rule) =>
        Rule.error("You have to fill out the alternative text.").required(),
      description: "Important for Seo and accessiblity.",
      options: {
        isHighlighted: true,
      },
    },
  ],
  preview: {
    select: {
      imageUrl: "asset.url",
      title: "alt",
    },
  },
}
AI Update

I understand the frustration! The way images appear in the Portable Text editor can definitely vary, and it sounds like you're not seeing the actual image previews you'd expect.

This Is Not a GraphQL Issue

First, let me address the GraphQL question: hoisting the GraphQL schema is completely unrelated to how content displays in the Studio editor. That's purely about API functionality, not the editing interface.

What You're Likely Experiencing

When custom block types (like your figure image type) are added to Portable Text arrays, how they display in the editor depends on your schema configuration. Your schema looks correct - you have a proper preview configuration which is the right approach for controlling how these blocks appear in Studio.

Your Schema Configuration

Your current preview setup should work to display images:

preview: {
  select: {
    imageUrl: "asset.url",
    title: "alt",
  },
}

This tells Sanity to show the image and use the alt text as the title. According to Sanity's documentation on Block Content, the preview configuration controls how blocks appear in various Studio contexts.

Things to Check

1. Verify your blockContent type includes the figure:

Make sure your Portable Text field properly references your figure type:

{
  name: 'body', // or whatever you call it
  type: 'array',
  of: [
    {type: 'block'},
    {type: 'figure'}, // your custom image type
  ]
}

2. Try these troubleshooting steps:

  • Restart your Studio dev server - Schema changes sometimes need a fresh start to take effect
  • Clear browser cache - Studio can cache schema information
  • Check the browser console - Look for any errors related to image loading or schema validation
  • Verify the image assets exist - Make sure the images have fully uploaded and processed in Sanity's asset pipeline

3. Consider enhancing your preview:

You might want to add a prepare function to your preview for more control:

preview: {
  select: {
    imageUrl: "asset.url",
    title: "alt",
  },
  prepare(selection) {
    const { imageUrl, title } = selection;
    return {
      title: title,
      subtitle: 'Image',
      media: /* your image component */
    };
  },
}

What Should Happen

With your schema configuration, Sanity Studio should be displaying a preview of your images within the Portable Text editor. The Portable Text specification supports custom blocks with rich previews, and your setup follows the correct pattern.

If you're seeing very minimal representations (like just text tokens or generic placeholders), it suggests either a caching issue that needs a Studio restart, or the images haven't fully processed in the asset pipeline.

If you're still experiencing issues after trying these steps, checking the browser console for errors would be the next step - there might be specific error messages that point to what's happening with your image display.

Show original thread
5 replies
Hey User! I don’t believe this is a hoisting issue and may just be change that was made to the studio itself. The docs do show the full image in the editor, so I’m confirming with the rest of the team.
Ok, so got clarity here! It’s actually due to the preview you’ve specified on your image schema. You can either remove the preview or add a
prepare()
option as well as a custom preview component . A simple example would be:
const Preview = ({value}) => {
  return <div>hello</div>
}
{
  name: 'someImageBlock',
  type: 'object',
  title: 'Image',

  preview: {
    select: {
      imageUrl: 'image.asset.url'
    },
    prepare(selection){
      return selection
    },
    component: Preview
  }
}
Thanks User! I will test this tonight!
Happy to help! Let me know how it goes!
Happy to help! Let me know how it goes!

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?