Implement loading.tsx and error.tsx at Every Route Segment
Impact: MEDIUM (prevents full-page loading states and uncontained error propagation)
Next.js App Router uses loading.tsx and error.tsx as automatic Suspense and Error Boundaries. Without them:
Missing loading.tsx: Suspense falls back to the nearest parent boundary — often the root layout — showing a full-page spinner instead of a granular skeleton for just the loading section
Missing error.tsx: Errors propagate up the component tree and crash the nearest parent layout, potentially taking down the entire page or even the app shell
Incorrect (missing boundary files):
app/├── layout.tsx ← Only error/loading boundary for the entire app├── page.tsx├── dashboard/│ ├── page.tsx ← ❌ No loading.tsx — full page spinner when navigating here│ ├── analytics/│ │ └── page.tsx ← ❌ No error.tsx — API failure crashes the entire dashboard│ └── settings/│ └── page.tsx└── profile/ └── page.tsx
// ❌ No loading state — user sees nothing while data loads// app/dashboard/page.tsxexport default async function Dashboard() { const data = await fetchDashboardData() // 2-3 second fetch, no visual feedback return <DashboardView data={data} />}// ❌ No error boundary — if fetchAnalytics throws, the dashboard layout crashes// app/dashboard/analytics/page.tsxexport default async function Analytics() { const data = await fetchAnalytics() // Throws → entire dashboard is blank return <AnalyticsView data={data} />}