From e86d6d1cee9792308553ea4f6a6aace9c927195f Mon Sep 17 00:00:00 2001 From: Rune Botten Date: Thu, 15 Aug 2024 15:45:32 -0700 Subject: [PATCH] fix(core): avoid attempting to render undefined image, which results in caught exceptions --- .../components/SanityDefaultPreview.tsx | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/sanity/src/core/preview/components/SanityDefaultPreview.tsx b/packages/sanity/src/core/preview/components/SanityDefaultPreview.tsx index 247e059e083..79021e6f323 100644 --- a/packages/sanity/src/core/preview/components/SanityDefaultPreview.tsx +++ b/packages/sanity/src/core/preview/components/SanityDefaultPreview.tsx @@ -83,16 +83,18 @@ export function SanityDefaultPreview(props: SanityDefaultPreviewProps): ReactEle return false } - if (isValidElementType(mediaProp)) { - return mediaProp - } - - if (isValidElement(mediaProp)) { - return mediaProp - } - - if (isImageSource(mediaProp)) { - return renderMedia + if (mediaProp) { + if (isValidElementType(mediaProp)) { + return mediaProp + } + + if (isValidElement(mediaProp)) { + return mediaProp + } + + if (isImageSource(mediaProp)) { + return renderMedia + } } // Handle image urls