fix: add SSR safety checks for window.matchMedia in PWA components
This commit is contained in:
@@ -44,8 +44,8 @@ export function InstallPrompt({ autoShow = false }: InstallPromptProps) {
|
|||||||
const { canInstall, installPrompt, isInstalled: pwaInstalled } = usePWA()
|
const { canInstall, installPrompt, isInstalled: pwaInstalled } = usePWA()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Check if app is already installed
|
// Check if app is already installed (client-side only)
|
||||||
if (window.matchMedia && window.matchMedia('(display-mode: standalone)').matches) {
|
if (typeof window !== 'undefined' && window.matchMedia && window.matchMedia('(display-mode: standalone)').matches) {
|
||||||
setIsInstalled(true)
|
setIsInstalled(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,7 +304,7 @@ export function useInstallPrompt() {
|
|||||||
const [isInstalled, setIsInstalled] = useState(false)
|
const [isInstalled, setIsInstalled] = useState(false)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (window.matchMedia && window.matchMedia('(display-mode: standalone)').matches) {
|
if (typeof window !== 'undefined' && window.matchMedia && window.matchMedia('(display-mode: standalone)').matches) {
|
||||||
setIsInstalled(true)
|
setIsInstalled(true)
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|||||||
@@ -101,6 +101,8 @@ export function ServiceWorkerProvider({ children }: { children: React.ReactNode
|
|||||||
}
|
}
|
||||||
|
|
||||||
const setupInstallPrompt = () => {
|
const setupInstallPrompt = () => {
|
||||||
|
if (typeof window === 'undefined') return
|
||||||
|
|
||||||
// Listen for beforeinstallprompt event
|
// Listen for beforeinstallprompt event
|
||||||
window.addEventListener('beforeinstallprompt', (e) => {
|
window.addEventListener('beforeinstallprompt', (e) => {
|
||||||
console.log('[PWA] Install prompt available')
|
console.log('[PWA] Install prompt available')
|
||||||
|
|||||||
Reference in New Issue
Block a user