Dashboard takes 1-2 seconds to load due to auth polling and duplicate API calls #45
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The dashboard at
/garage/dashboardtakes 1-2 seconds to become interactive after page load. Browser debugging revealed multiple performance bottlenecks in the authentication flow and data fetching.Root Cause Analysis
Issue 1: Auth Gate Polling Delay (~700-1000ms)
File:
frontend/src/core/auth/auth-gate.ts:128-152The
useIsAuthInitializedhook polls every 50-150ms (exponential backoff) instead of using event-based notification:waitForAuthInit()function that resolves immediately, but it's not used by the React hookIssue 2: Artificial 100ms Delay
File:
frontend/src/core/auth/Auth0Provider.tsx:185-188Hardcoded delay before token initialization starts.
Issue 3: Duplicate API Calls
File:
frontend/src/features/dashboard/hooks/useDashboardData.tsTwo queries both call the same endpoints:
useDashboardSummaryanduseVehiclesNeedingAttentionboth callvehiclesApi.getAll()Network trace shows:
/api/vehiclescalled TWICE/api/maintenance/schedules/vehicle/{id}called 6 times (3 vehicles x 2 queries)Issue 4: Sequential vs Parallel Fetching
File:
frontend/src/features/dashboard/hooks/useDashboardData.ts:90-91Uses sequential
for...ofloop instead ofPromise.all()for maintenance schedule fetching.Performance Impact
Acceptance Criteria
Plan
Milestone 1: Fix Auth Gate Polling
useIsAuthInitializedwith event-based subscriptionwaitForAuthInit()promise or add a subscription mechanismMilestone 2: Remove Artificial Delay
Auth0Provider.tsxMilestone 3: Deduplicate Dashboard API Calls
Promise.all()for parallel maintenance schedule fetchingMilestone: Implementation Complete
Phase: Execution | Agent: Developer | Status: PASS
Changes Implemented
Milestone 1: Auth Gate Polling Fix
File:
frontend/src/core/auth/auth-gate.tsuseIsAuthInitializedhook with event subscriptionMilestone 2: Token Delay Removal
File:
frontend/src/core/auth/Auth0Provider.tsxMilestone 3: Dashboard API Deduplication
File:
frontend/src/features/dashboard/hooks/useDashboardData.tsuseDashboardDatahook that fetches all data onceuseDashboardSummaryanduseVehiclesNeedingAttentionnow derive from unified queryQuality Checks
Commit
b6af238- perf: fix dashboard load performance with auth gate and API deduplication (refs #45)Verdict: PASS | Next: Create PR and move to status/review