1.9 KiB
1.9 KiB
Mission Control Documents Fix - Summary
Problem
Documents page stuck on "Loading documents..." indefinitely even though API endpoint /api/documents was working correctly.
Root Cause Analysis
The API endpoint was properly configured and environment variables were set on Vercel. The issue was that:
- The API route was already fixed with proper error handling
- The useDocuments hook had good error handling but lacked a timeout mechanism
- The issue was likely related to fetch hanging or taking too long without proper timeout handling
Changes Made
1. Updated hooks/useDocuments.ts
- Added
fetchWithTimeouthelper function with 10-second timeout - Added abort controller to cancel fetch if it takes too long
- Added proper cleanup with
isMountedflag to prevent state updates after unmount - Improved console logging with
[useDocuments]prefix for easier debugging - Added better error handling for timeout scenarios
2. Verified app/api/documents/route.ts
- API route already had proper environment variable validation
- Returns clear error messages if env vars are missing
- Uses service role key for Supabase access
Verification
- API endpoint returns all 3 documents correctly from Supabase
- Build succeeds without errors
- Deployed to production successfully
Deployment URLs
- Production: https://mission-control-rho-pink.vercel.app
- API Test: https://mission-control-rho-pink.vercel.app/api/documents
Next Steps (for user)
- Visit https://mission-control-rho-pink.vercel.app/documents in browser
- Check browser console for
[useDocuments]log messages - If still stuck on loading, check Network tab to see if fetch is completing
- If there's an error, the page should now display it with a retry button
Environment Variables (verified on Vercel)
NEXT_PUBLIC_SUPABASE_URL✓NEXT_PUBLIC_SUPABASE_ANON_KEY✓SUPABASE_SERVICE_ROLE_KEY✓