fix: add SSR safety checks for navigator and window objects
This commit is contained in:
@@ -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
|
||||
// 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)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user