
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeWhen 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:
props object (which includes renderDefault)renderDefault(props) to render the default preview UI with all its controlsThis 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:
title might be undefined or emptytitle?.split()) to prevent errorsrenderDefault pattern works for any custom component in Sanity Studio (field, input, item, or preview components)renderDefault in a container to add custom styling around the default UIThis same pattern applies whenever you want to enhance rather than completely replace Sanity's default form components!
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store