mirror of
https://github.com/dergigi/boris.git
synced 2025-12-17 14:44:26 +01:00
chore: remove remaining console.log debug statements
Remove all console.log statements from Service Worker registration and ReaderHeader image loading code, keeping only console.error and console.warn for actual error handling.
This commit is contained in:
@@ -37,17 +37,6 @@ const ReaderHeader: React.FC<ReaderHeaderProps> = ({
|
|||||||
onHighlightCountClick
|
onHighlightCountClick
|
||||||
}) => {
|
}) => {
|
||||||
const cachedImage = useImageCache(image)
|
const cachedImage = useImageCache(image)
|
||||||
|
|
||||||
// Debug: Log image loading state
|
|
||||||
React.useEffect(() => {
|
|
||||||
if (image) {
|
|
||||||
console.log('[reader-header] Image provided:', image)
|
|
||||||
if (cachedImage) {
|
|
||||||
console.log('[reader-header] Using cached image URL:', cachedImage)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [image, cachedImage])
|
|
||||||
|
|
||||||
const { textColor } = useAdaptiveTextColor(cachedImage)
|
const { textColor } = useAdaptiveTextColor(cachedImage)
|
||||||
const formattedDate = published ? format(new Date(published * 1000), 'MMM d, yyyy') : null
|
const formattedDate = published ? format(new Date(published * 1000), 'MMM d, yyyy') : null
|
||||||
const isLongSummary = summary && summary.length > 150
|
const isLongSummary = summary && summary.length > 150
|
||||||
@@ -94,16 +83,8 @@ const ReaderHeader: React.FC<ReaderHeaderProps> = ({
|
|||||||
<img
|
<img
|
||||||
src={cachedImage}
|
src={cachedImage}
|
||||||
alt={title || 'Article image'}
|
alt={title || 'Article image'}
|
||||||
onLoad={() => {
|
|
||||||
console.log('[reader-header] ✅ Image loaded successfully:', cachedImage)
|
|
||||||
}}
|
|
||||||
onError={(e) => {
|
onError={(e) => {
|
||||||
console.error('[reader-header] ❌ Image failed to load:', cachedImage, {
|
console.error('[reader-header] Image failed to load:', cachedImage, e)
|
||||||
error: e,
|
|
||||||
target: e.currentTarget,
|
|
||||||
naturalWidth: e.currentTarget.naturalWidth,
|
|
||||||
naturalHeight: e.currentTarget.naturalHeight
|
|
||||||
})
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
61
src/main.tsx
61
src/main.tsx
@@ -12,94 +12,45 @@ if ('serviceWorker' in navigator) {
|
|||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
const swPath = '/sw.js'
|
const swPath = '/sw.js'
|
||||||
|
|
||||||
console.log('[sw-registration] Attempting to register Service Worker:', swPath, {
|
|
||||||
isProd: import.meta.env.PROD,
|
|
||||||
isDev: import.meta.env.DEV,
|
|
||||||
hasController: !!navigator.serviceWorker.controller
|
|
||||||
})
|
|
||||||
|
|
||||||
// Check if already registered/active first
|
// Check if already registered/active first
|
||||||
navigator.serviceWorker.getRegistrations().then(async (registrations) => {
|
navigator.serviceWorker.getRegistrations().then(async (registrations) => {
|
||||||
console.log('[sw-registration] Existing registrations:', registrations.length)
|
|
||||||
|
|
||||||
if (registrations.length > 0) {
|
if (registrations.length > 0) {
|
||||||
const existingReg = registrations[0]
|
return registrations[0]
|
||||||
console.log('[sw-registration] Service Worker already registered:', {
|
|
||||||
scope: existingReg.scope,
|
|
||||||
active: !!existingReg.active,
|
|
||||||
installing: !!existingReg.installing,
|
|
||||||
waiting: !!existingReg.waiting,
|
|
||||||
controller: !!navigator.serviceWorker.controller
|
|
||||||
})
|
|
||||||
|
|
||||||
if (existingReg.active) {
|
|
||||||
console.log('[sw-registration] ✅ Service Worker is active')
|
|
||||||
}
|
|
||||||
return existingReg
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not registered yet, try to register
|
// Not registered yet, try to register
|
||||||
// In dev mode, use the dev Service Worker for testing
|
// In dev mode, use the dev Service Worker for testing
|
||||||
if (import.meta.env.DEV) {
|
if (import.meta.env.DEV) {
|
||||||
const devSwPath = '/sw-dev.js'
|
const devSwPath = '/sw-dev.js'
|
||||||
console.log('[sw-registration] Dev mode - using development Service Worker:', devSwPath)
|
|
||||||
try {
|
try {
|
||||||
// Check if dev SW exists
|
// Check if dev SW exists
|
||||||
const response = await fetch(devSwPath)
|
const response = await fetch(devSwPath)
|
||||||
const contentType = response.headers.get('content-type') || ''
|
const contentType = response.headers.get('content-type') || ''
|
||||||
const isJavaScript = contentType.includes('javascript') || contentType.includes('application/javascript')
|
const isJavaScript = contentType.includes('javascript') || contentType.includes('application/javascript')
|
||||||
|
|
||||||
console.log('[sw-registration] Dev SW check:', {
|
|
||||||
status: response.status,
|
|
||||||
contentType,
|
|
||||||
isJavaScript
|
|
||||||
})
|
|
||||||
|
|
||||||
if (response.ok && isJavaScript) {
|
if (response.ok && isJavaScript) {
|
||||||
console.log('[sw-registration] Development Service Worker available, proceeding with registration')
|
|
||||||
return await navigator.serviceWorker.register(devSwPath, { scope: '/' })
|
return await navigator.serviceWorker.register(devSwPath, { scope: '/' })
|
||||||
} else {
|
} else {
|
||||||
console.warn('[sw-registration] ⚠️ Development Service Worker not available:', {
|
console.warn('[sw-registration] Development Service Worker not available')
|
||||||
status: response.status,
|
|
||||||
contentType
|
|
||||||
})
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn('[sw-registration] ⚠️ Could not load development Service Worker:', err)
|
console.warn('[sw-registration] Could not load development Service Worker:', err)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// In production, just register directly
|
// In production, just register directly
|
||||||
console.log('[sw-registration] No existing registration, attempting to register:', swPath)
|
|
||||||
return await navigator.serviceWorker.register(swPath)
|
return await navigator.serviceWorker.register(swPath)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(registration => {
|
.then(registration => {
|
||||||
if (!registration) return
|
if (!registration) return
|
||||||
|
|
||||||
console.log('[sw-registration] ✅ Service Worker registration successful:', {
|
|
||||||
scope: registration.scope,
|
|
||||||
active: !!registration.active,
|
|
||||||
installing: !!registration.installing,
|
|
||||||
waiting: !!registration.waiting,
|
|
||||||
controller: !!navigator.serviceWorker.controller
|
|
||||||
})
|
|
||||||
|
|
||||||
// Wait for Service Worker to activate
|
// Wait for Service Worker to activate
|
||||||
if (registration.active) {
|
if (registration.installing) {
|
||||||
console.log('[sw-registration] Service Worker is already active and controlling page')
|
|
||||||
} else if (registration.installing) {
|
|
||||||
console.log('[sw-registration] Service Worker is installing...')
|
|
||||||
registration.installing.addEventListener('statechange', () => {
|
registration.installing.addEventListener('statechange', () => {
|
||||||
const state = registration.installing?.state
|
// Service Worker state changed
|
||||||
console.log('[sw-registration] Service Worker state changed:', state)
|
|
||||||
if (state === 'activated') {
|
|
||||||
console.log('[sw-registration] ✅ Service Worker activated and ready')
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
} else if (registration.waiting) {
|
|
||||||
console.log('[sw-registration] Service Worker is waiting to activate')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for updates periodically (production only)
|
// Check for updates periodically (production only)
|
||||||
@@ -111,11 +62,9 @@ if ('serviceWorker' in navigator) {
|
|||||||
|
|
||||||
// Handle service worker updates
|
// Handle service worker updates
|
||||||
registration.addEventListener('updatefound', () => {
|
registration.addEventListener('updatefound', () => {
|
||||||
console.log('[sw-registration] Service Worker update found')
|
|
||||||
const newWorker = registration.installing
|
const newWorker = registration.installing
|
||||||
if (newWorker) {
|
if (newWorker) {
|
||||||
newWorker.addEventListener('statechange', () => {
|
newWorker.addEventListener('statechange', () => {
|
||||||
console.log('[sw-registration] New Service Worker state:', newWorker.state)
|
|
||||||
if (newWorker.state === 'installed' && navigator.serviceWorker.controller) {
|
if (newWorker.state === 'installed' && navigator.serviceWorker.controller) {
|
||||||
// New service worker available
|
// New service worker available
|
||||||
const updateAvailable = new CustomEvent('sw-update-available')
|
const updateAvailable = new CustomEvent('sw-update-available')
|
||||||
|
|||||||
Reference in New Issue
Block a user