# đ DEBUGGING GUIDE - Music State ## Problem: `window.publicMusicState` is undefined ### Possible Causes & Solutions --- ### 1ī¸âŖ **Debug Utility Not Loaded** **Check:** Open browser console and look for: ``` [Debug] State exposed to window object: â window.publicMusicState â window.adminNavState â window.adminAuthState ``` **If NOT visible:** - Debug utility not imported - Check `src/app/layout.tsx` has: `import '@/lib/debug-state';` --- ### 2ī¸âŖ **Timing Issue - Console.log Too Early** **Problem:** You're checking `window.publicMusicState` before it's exposed. **Solution:** Wait for page to fully load, then check: ```javascript // In browser console, type: window.publicMusicState ``` **Expected Output:** ```javascript { isPlaying: false, currentSong: null, currentSongIndex: -1, musikData: [], currentTime: 0, duration: 0, volume: 70, isMuted: false, isRepeat: false, isShuffle: false, isLoading: true, isPlayerOpen: false, error: null, playSong: Æ, togglePlayPause: Æ, // ... all methods } ``` --- ### 3ī¸âŖ **Alternative Debug Methods** If `window.publicMusicState` still undefined, try these: #### Method 1: Use Helper Function ```javascript // In browser console: window.getMusicState() ``` #### Method 2: Import Directly (in console) ```javascript // This won't work in console, but you can add to your component: import { publicMusicState } from '@/state/public/publicMusicState'; console.log('Music State:', publicMusicState); ``` #### Method 3: Check from Component Add to any component: ```typescript useEffect(() => { console.log('Music State:', window.publicMusicState); }, []); ``` --- ### 4ī¸âŖ **Verify Import Chain** Check if all files are properly imported: ``` src/app/layout.tsx ââ import '@/lib/debug-state' ââ import { publicMusicState } from '@/state/public/publicMusicState' ââ Exports proxy state ``` --- ### 5ī¸âŖ **Check Browser Console for Errors** Look for errors like: - â `Cannot find module '@/state/public/publicMusicState'` - â `publicMusicState is not defined` - â `Failed to load module` **If you see these:** - Check TypeScript compilation: `bunx tsc --noEmit` - Check file paths are correct - Restart dev server: `bun run dev` --- ### 6ī¸âŖ **Manual Test - Add to Component** Temporarily add to any page component: ```typescript 'use client'; import { publicMusicState } from '@/state/public/publicMusicState'; import { useEffect } from 'react'; export default function TestPage() { useEffect(() => { console.log('đĩ Music State:', publicMusicState); console.log('đĩ Is Playing:', publicMusicState.isPlaying); console.log('đĩ Current Song:', publicMusicState.currentSong); }, []); return