From ce448adc6316adb5a173cb645b858c9f335f96ca Mon Sep 17 00:00:00 2001 From: Andrei Date: Fri, 10 Oct 2025 12:18:01 +0000 Subject: [PATCH] fix: add SSR safety checks for navigator and window objects --- app/[locale]/bible/reader.tsx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/[locale]/bible/reader.tsx b/app/[locale]/bible/reader.tsx index 3cc11ab..3b8615a 100644 --- a/app/[locale]/bible/reader.tsx +++ b/app/[locale]/bible/reader.tsx @@ -345,11 +345,13 @@ export default function BibleReaderNew({ initialVersion, initialBook, initialCha console.log('You are now offline. Only downloaded content is available.') } - // Set initial state - setIsOnline(navigator.onLine) + // Set initial state (client-side only) + if (typeof window !== 'undefined') { + setIsOnline(navigator.onLine) + } // Check for offline mode preference - const offlineParam = new URLSearchParams(window.location.search).get('offline') + const offlineParam = typeof window !== 'undefined' ? new URLSearchParams(window.location.search).get('offline') : null if (offlineParam === 'true') { setIsOfflineMode(true) } @@ -902,12 +904,12 @@ export default function BibleReaderNew({ initialVersion, initialBook, initialCha const maxChapters = currentBook?.chapters?.length || 1 const handleShare = async () => { - if (!selectedBook || !selectedChapter) return + if (!selectedBook || !selectedChapter || typeof window === 'undefined') return const shareUrl = `${window.location.origin}/${locale}/bible?version=${selectedVersion}&book=${selectedBook}&chapter=${selectedChapter}` const shareText = currentBook ? `${currentBook.name} ${selectedChapter}` : `Chapter ${selectedChapter}` - if (navigator.share) { + if (typeof navigator !== 'undefined' && navigator.share) { try { await navigator.share({ title: shareText, @@ -921,7 +923,7 @@ export default function BibleReaderNew({ initialVersion, initialBook, initialCha console.error('Failed to copy link:', clipError) } } - } else { + } else if (typeof navigator !== 'undefined') { // Fallback: copy to clipboard try { await navigator.clipboard.writeText(shareUrl) @@ -1067,12 +1069,16 @@ export default function BibleReaderNew({ initialVersion, initialBook, initialCha } const handleCopyVerse = (verse: BibleVerse) => { + if (typeof navigator === 'undefined') return + const text = `${currentBook?.name} ${selectedChapter}:${verse.verseNum} - ${verse.text}` navigator.clipboard.writeText(text).then(() => { setCopyFeedback({ open: true, message: t('copied') }) + }).catch(err => { + console.error('Failed to copy verse:', err) }) }