Debugging form.component.preview for YouTube thumbnail in Portable Text

7 replies
Last updated: Nov 30, 2025
Hello, I’m hoping to get some tips on debugging
form.component.preview
for a YouTube thumbnail located within a portable content editor?
AI Update

When debugging form.component.preview for a YouTube thumbnail in Portable Text, the most common issue is that your custom preview component completely replaces the default UI, hiding the input fields and edit controls.

The key solution is to use the renderDefault function that's passed to your preview component. This renders the default preview UI, which includes the edit controls and field labels. Here's how to fix it:

const YouTubePreview = (props) => {
  const { renderDefault, title } = props;
  const url = title?.split(" ")[1];
  const id = getYouTubeID(url);
  const opts = {
    height: "183",
    width: "300",
  };
  
  return (
    <div>
      {renderDefault(props)}
      <YTPreview opts={opts} videoId={id} />
    </div>
  );
};

The critical changes are:

  1. Accept the full props object (which includes renderDefault)
  2. Call renderDefault(props) to render the default preview UI with all its controls
  3. Add your custom preview below it

This pattern is documented in the Form Components API section on renderDefault. The renderDefault function preserves all the built-in functionality like the edit button (the "..." menu), field labels, and double-click-to-edit behavior, while still letting you add your custom YouTube preview.

Without renderDefault, your custom component completely replaces the default UI, making it difficult for editors to access the input fields. You might notice they can only edit by making the preview very small and double-clicking, which isn't intuitive. By including renderDefault, you get the best of both worlds: your custom preview plus all the standard editing controls.

Additional debugging tips:

  • Make sure to handle cases where title might be undefined or empty
  • Consider using optional chaining (title?.split()) to prevent errors
  • The renderDefault pattern works for any custom component in Sanity Studio (field, input, item, or preview components)
  • You can wrap renderDefault in a container to add custom styling around the default UI

This same pattern applies whenever you want to enhance rather than completely replace Sanity's default form components!

Show original thread
7 replies

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?