From 1c70098ba67a07804a042d4add034ca03072f648 Mon Sep 17 00:00:00 2001 From: "shakespeare.diy" Date: Wed, 18 Feb 2026 23:23:20 -0600 Subject: [PATCH] Fix initialization order for previewImages and previewVideos Move image/video extraction before hasPreviewableContent check to avoid accessing variables before initialization. Co-authored-by: shakespeare.diy --- src/components/ComposeBox.tsx | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/components/ComposeBox.tsx b/src/components/ComposeBox.tsx index 5a3a2d87..b86781c6 100644 --- a/src/components/ComposeBox.tsx +++ b/src/components/ComposeBox.tsx @@ -197,13 +197,24 @@ export function ComposeBox({ onSuccess, placeholder = "What's on your mind?", co [detectedEmbeds, removedEmbeds] ); + // Extract images and videos for preview mode + const previewImages = useMemo(() => { + if (!content) return []; + const urlRegex = /https?:\/\/[^\s]+\.(jpg|jpeg|png|gif|webp|svg)(\?[^\s]*)?/gi; + return content.match(urlRegex) || []; + }, [content]); + + const previewVideos = useMemo(() => { + if (!content) return []; + const urlRegex = /https?:\/\/[^\s]+\.(mp4|webm|mov)(\?[^\s]*)?/gi; + return content.match(urlRegex) || []; + }, [content]); + // Check if content has any previewable content (link previews, images, or videos) const hasPreviewableContent = useMemo(() => { return visibleEmbeds.length > 0 || previewImages.length > 0 || previewVideos.length > 0; }, [visibleEmbeds, previewImages, previewVideos]); - - // Include quoted event if provided and not removed const quotedEventId = quotedEvent ? nip19.neventEncode({ id: quotedEvent.id, author: quotedEvent.pubkey }) : null; const quotedEventKey = quotedEventId ? `nostr:${quotedEventId}` : null; @@ -227,19 +238,6 @@ export function ComposeBox({ onSuccess, placeholder = "What's on your mind?", co }; }, [user, content]); - // Extract images and videos for preview mode - const previewImages = useMemo(() => { - if (!content) return []; - const urlRegex = /https?:\/\/[^\s]+\.(jpg|jpeg|png|gif|webp|svg)(\?[^\s]*)?/gi; - return content.match(urlRegex) || []; - }, [content]); - - const previewVideos = useMemo(() => { - if (!content) return []; - const urlRegex = /https?:\/\/[^\s]+\.(mp4|webm|mov)(\?[^\s]*)?/gi; - return content.match(urlRegex) || []; - }, [content]); - const insertEmoji = useCallback((emoji: string) => { const textarea = textareaRef.current; if (textarea) {