From 1217fe58be7a3f85d4a072e2e2692157db910dad Mon Sep 17 00:00:00 2001 From: Rudy Fraser Date: Tue, 30 Jun 2026 16:21:46 -0400 Subject: [PATCH] fix(community-posts): YouTube iframe + gallery render guards #9 IFRAME_HOST hardcoded to https://blacksky.community meant any non-canonical parent host (staging.blacksky.community, local dev, preview deploys) framed cross-origin and got blocked by the iframe server's X-Frame-Options: SAMEORIGIN. Read window.location.origin so the iframe always loads same-origin with the SPA. #10 ImageEmbed.tsx and MediaPreview.tsx assumed embed.view.items was always an array. A malformed gallery#view (e.g. items missing) threw TypeError on .filter / for-of and ErrorBoundary locked the whole page. Wrap in Array.isArray guards so a future appview regression degrades to 'no media' instead of 'page crashes.' --- src/components/MediaPreview.tsx | 2 +- src/components/Post/Embed/ImageEmbed.tsx | 18 +++++++++++------- src/lib/strings/embed-player.ts | 4 ++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/components/MediaPreview.tsx b/src/components/MediaPreview.tsx index 7b0e38e0b..e6697df6c 100644 --- a/src/components/MediaPreview.tsx +++ b/src/components/MediaPreview.tsx @@ -57,7 +57,7 @@ export function Embed({ // of filter().slice().map() so we stop at 4 viewable items rather than // walking every item in a 10-image gallery. const tiles: React.ReactNode[] = [] - for (const item of e.view.items) { + for (const item of Array.isArray(e.view.items) ? e.view.items : []) { if (tiles.length >= 4) break if (!AppBskyEmbedGallery.isViewImage(item)) continue if (peekable) { diff --git a/src/components/Post/Embed/ImageEmbed.tsx b/src/components/Post/Embed/ImageEmbed.tsx index 9d4730206..1118b90e8 100644 --- a/src/components/Post/Embed/ImageEmbed.tsx +++ b/src/components/Post/Embed/ImageEmbed.tsx @@ -31,13 +31,17 @@ export function ImageEmbed({ const {openLightbox} = useLightboxControls() const images: AppBskyEmbedImages.ViewImage[] = embed.type === 'gallery' - ? embed.view.items.filter(AppBskyEmbedGallery.isViewImage).map(item => ({ - thumb: item.thumbnail, - fullsize: item.fullsize, - alt: item.alt, - aspectRatio: item.aspectRatio, - })) - : embed.view.images + ? (Array.isArray(embed.view.items) ? embed.view.items : []) + .filter(AppBskyEmbedGallery.isViewImage) + .map(item => ({ + thumb: item.thumbnail, + fullsize: item.fullsize, + alt: item.alt, + aspectRatio: item.aspectRatio, + })) + : Array.isArray(embed.view.images) + ? embed.view.images + : [] const useExpandedLayout = embed.type === 'gallery' ? images.length > MAX_GRID_IMAGES diff --git a/src/lib/strings/embed-player.ts b/src/lib/strings/embed-player.ts index 40abc13fa..6614836f9 100644 --- a/src/lib/strings/embed-player.ts +++ b/src/lib/strings/embed-player.ts @@ -6,8 +6,8 @@ const {height: SCREEN_HEIGHT} = Dimensions.get('window') const IFRAME_HOST = IS_WEB ? // @ts-ignore only for web - window.location.host === 'localhost:8100' - ? 'http://localhost:8100' + typeof window !== 'undefined' + ? window.location.origin : 'https://blacksky.community' : __DEV__ && !process.env.JEST_WORKER_ID ? 'http://localhost:8100' -- knotmirror 0.0.1