Next.js Labs
App Router projects running in the page, with no server and no build. A worker in a sandboxed frame plays the server, using React's real server components. Change a file and press Run, or Ctrl/⌘+Enter.
This is a compatible preview, not Next.js itself. There is no server rendering of client components, the sandbox blocks other sites, and only react, react-dom and next/* can be imported. The README lists what works and what differs.
Jump to: Server and client components · Routes and layouts · Server actions · Loading and error pages · Route handlers · Streaming · Search in the URL · Cookies and redirects · Optimistic updates · Navigation · TypeScript and Tailwind
Server and client components
A server component can be async and has no window. A client component has state. "use client" marks where one becomes the other.
Routes and layouts
Folders are URLs. Follow the links, or type a path such as /blog/first in the preview's address bar.
Server actions
Sign the guestbook. The form calls a function on the server, then the page renders again with the new row.
Loading and error pages
loading.jsx shows while a page streams, and error.jsx catches what it throws.
Route handlers
fetch('/api/double') reaches the handler in route.js, which runs on the server thread.
Streaming with Suspense
Each panel waits for its own data. The heading arrives first, and each panel replaces its placeholder as soon as it is ready, in whatever order they finish. Press refresh in the address bar to watch it again.
Search in the URL
The search box writes to the URL, and the server component reads it back through searchParams. Type something, press a tag, and see the address bar change. Back and Forward work.
Cookies and redirects
A small sign-in. The home page sends you to /login until a cookie says otherwise, and the actions set the cookie, clear it and redirect. Sign in with any name, or none to see the error. The cookie lasts until the next Run.
Optimistic updates
A new task appears at once, greyed out, while the slow action runs on the server. Each Remove button is an action written inside the loop, and it closes over its own task.
TypeScript and Tailwind
.tsx files work, with their types removed rather than checked. A project that imports Tailwind downloads it; others don't.