← Back to Demo Hub
Test #9React & Next.js Specific

localStorage SSR Error

Accessing browser-only APIs like localStorage on the server side.

📋 Demo Instructions

  1. Click the "Trigger Error" button below
  2. Open browser console (F12) to see the error
  3. Wait 5-10 seconds for the error to be captured
  4. Go to Dashboard → Performance Monitoring
  5. Click "Fix with Carla" on the error
  6. Review the generated PR
🌍 Real-World Scenario
Component uses localStorage to persist user preferences or auth tokens, but Next.js tries to render it on the server during SSR where localStorage doesn't exist.
✅ Expected Fix
Add typeof window !== 'undefined' check before accessing browser APIs, or use useEffect to access them only on the client side.
Fix Confidence:HIGH

💻 Buggy Code

// Buggy Code
const userData = localStorage.getItem('userData');
setUser(JSON.parse(userData));
// ReferenceError: localStorage is not defined (during SSR)

🔴 Error Log

Waiting for error to be triggered...