Loading Depth Study
Preparing your workspace
Next.js provides conventions for displaying loading UI, handling route-level errors, and showing not-found pages.
Real applications need to handle more than the successful state. loading.tsx can provide immediate route loading UI, error.tsx can provide a recovery experience for errors, and notFound() can represent missing resources. Designing these states improves user experience and makes failures more predictable. Errors should be logged appropriately while user-facing messages remain safe and understandable.
A course page can show a loading skeleton while data is being prepared, a friendly error state when a request fails, and a not-found page when the course does not exist.
import { notFound } from 'next/navigation';
export default async function CoursePage() {
const course = await getCourse();
if (!course) {
notFound();
}
return <h1>{course.title}</h1>;
}The route displays the configured not-found experience when the requested course does not exist.