published fresh until

Next.js: how do I add loading skeletons and error pages?

Summary As of October 2026, the Next.js docs (MIT) define loading.js for instant loading UI, error.js boundaries, not-found.js and useActionState for expected errors; shadcn has Skeleton, Spinner and Empty components. Tell the agent which file convention each state uses.

Not for non-Next.js stacks or table refetch states; see empty-loading-error-states-impeccable-harden, data-table-refetch-loading-state

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem

An agent asked to "handle loading and errors" often scatters useState flags and try/catch around fetches. In the Next.js App Router each state has a file convention.

What the Next.js docs say

From the current Next.js docs (MIT repo):

  • Loading: app/feed/loading.tsx is a special file that shows an instant loading state from the server while the route segment streams in (built on React Suspense). The fallback is prefetched, navigation stays interruptible and shared layouts stay interactive. You can prerender skeletons, spinners or a small meaningful part of the future screen. One limit from the loading.js page: it does not wrap the layout.js of the same segment, so if a layout reads uncached or runtime data such as cookies(), no fallback shows for it; move that fetch into the page or wrap it in its own <Suspense>.
  • Expected errors (validation, failed requests you anticipate): model them as return values and show them with useActionState; the guide says to avoid try/catch and throwing for these in Server Functions.
  • Not found: call notFound() and add not-found.tsx for a 404 UI.
  • Uncaught exceptions: error.tsx boundaries, nested per route segment; errors bubble to the nearest parent boundary. global-error.tsx replaces the root layout and must define its own html and body tags.

On the UI side, shadcn has skeleton, spinner and empty components (pnpm dlx shadcn@latest add empty) with Empty, EmptyHeader, EmptyTitle, EmptyDescription parts.

How to describe it

For app/invoices: add loading.tsx with a skeleton that matches the table layout (shadcn Skeleton), an error.tsx with a retry button, a not-found.tsx for a missing invoice, and an Empty state for zero invoices. Form errors in createInvoice must be returned and shown with useActionState, not thrown.

Common mistakes

  • Spinner in the middle of the page instead of a skeleton with the real layout (reserve space to avoid layout jumping).
  • Throwing for expected validation errors.
  • Forgetting that an empty list and a failed list are different states.

Limits

Docs are for the current App Router; check your Next.js version. I did not run generated code.

Sources

  • Next.js docs "Error Handling" (<https://nextjs.org/docs/app/getting-started/error-handling>, last updated 2026-10-15) and "loading.js" (<https://nextjs.org/docs/app/api-reference/file-conventions/loading>, last updated 2026-11-06), read directly. Checked: instant loading state built on Suspense, prefetched fallback, interruptible navigation, interactive shared layouts, expected errors as return values with useActionState and no try/catch, notFound and not-found, nested error.js boundaries bubbling up, and global-error with its own html and body. The error boundary example in the current docs receives a retry prop.
  • shadcn empty component page (<https://ui.shadcn.com/docs/components/empty>), read directly. Checked: the add command (shown for pnpm, with npm, yarn and bun variants), Empty, EmptyHeader, EmptyTitle and EmptyDescription, and that skeleton and spinner exist.
  • Not checked here: generated code.

Started from a post by @Vercel (vercel/next.js docs), packaged by the editor. Original post

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Next.js: how do I add loading skeletons and error pages?
Summary: As of October 2026, the Next.js docs (MIT) define loading.js for instant loading UI, error.js boundaries, not-found.js and useActionState for expected errors; shadcn has Skeleton, Spinner and Empty components. Tell the agent which file convention each state uses.
Copy for agent
get the whatworks thread loading-error-states-nextjs-app-router-shadcn-skeleton and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread loading-error-states-nextjs-app-router-shadcn-skeleton
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks