From 09b8450bffacbe66599c227985bfc31e4e19afb1 Mon Sep 17 00:00:00 2001 From: Andrei Date: Fri, 10 Oct 2025 12:21:47 +0000 Subject: [PATCH] fix: add SSR safety checks for window.matchMedia in PWA components --- components/pwa/install-prompt.tsx | 6 +++--- components/pwa/service-worker-provider.tsx | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/components/pwa/install-prompt.tsx b/components/pwa/install-prompt.tsx index c1f2d40..a1996bf 100644 --- a/components/pwa/install-prompt.tsx +++ b/components/pwa/install-prompt.tsx @@ -44,8 +44,8 @@ export function InstallPrompt({ autoShow = false }: InstallPromptProps) { const { canInstall, installPrompt, isInstalled: pwaInstalled } = usePWA() useEffect(() => { - // Check if app is already installed - if (window.matchMedia && window.matchMedia('(display-mode: standalone)').matches) { + // Check if app is already installed (client-side only) + if (typeof window !== 'undefined' && window.matchMedia && window.matchMedia('(display-mode: standalone)').matches) { setIsInstalled(true) } @@ -304,7 +304,7 @@ export function useInstallPrompt() { const [isInstalled, setIsInstalled] = useState(false) useEffect(() => { - if (window.matchMedia && window.matchMedia('(display-mode: standalone)').matches) { + if (typeof window !== 'undefined' && window.matchMedia && window.matchMedia('(display-mode: standalone)').matches) { setIsInstalled(true) } }, []) diff --git a/components/pwa/service-worker-provider.tsx b/components/pwa/service-worker-provider.tsx index c810a44..ba180e3 100644 --- a/components/pwa/service-worker-provider.tsx +++ b/components/pwa/service-worker-provider.tsx @@ -101,6 +101,8 @@ export function ServiceWorkerProvider({ children }: { children: React.ReactNode } const setupInstallPrompt = () => { + if (typeof window === 'undefined') return + // Listen for beforeinstallprompt event window.addEventListener('beforeinstallprompt', (e) => { console.log('[PWA] Install prompt available')