Softechinfra
Development

Next.js 13 Features: App Router & Server Components Guide

Master Next.js 13 with app directory, React Server Components, streaming, and Suspense. Complete migration guide included.

Hrishikesh BaidyaHrishikesh Baidya
April 5, 202211 min read
Next.js 13 Features: App Router & Server Components Guide

Next.js 13 represents the biggest update to the framework, introducing the app directory, server components, and more. Our development team at Softechinfra has migrated several production applications to Next.js 13.

70%
Smaller Bundle Size
3x
Faster Cold Starts
0
Client JS for RSC
500K+
Weekly Downloads

Major New Features

App Directory

💡 New File-Based Routing

The app directory introduces a more intuitive routing system with special files for layouts, loading states, and error handling.

New File-Based Routing

code
app/
  page.tsx          # Route: /
  about/
    page.tsx        # Route: /about
  blog/
    [slug]/
      page.tsx      # Route: /blog/:slug
    Special Files
  • page.tsx: Route UI
  • layout.tsx: Shared UI
  • loading.tsx: Loading state
  • error.tsx: Error handling
  • not-found.tsx: 404 page

React Server Components

Server Components (Default)

typescript
// This runs on the server
async function ProductList() {
  const products = await db.products.findMany();
  return (
    <ul>
      {products.map(p => <li key={p.id}>{p.name}</li>)}
    </ul>
  );
}

Client Components

typescript
'use client';

import { useState } from 'react';

export function Counter() {
  const [count, setCount] = useState(0);
  return <button onClick={() => setCount(count + 1)}>{count}</button>;
}

Streaming and Suspense

Built-in Streaming

typescript
// loading.tsx provides instant loading state
export default function Loading() {
  return <Skeleton />;
}

Suspense Boundaries

typescript
import { Suspense } from 'react';

export default function Page() {
  return (
    <div>
      <h1>Dashboard</h1>
      <Suspense fallback={<Loading />}>
        <SlowComponent />
      </Suspense>
    </div>
  );
}

Data Fetching

Server Components Data Fetching

typescript
async function getData() {
  const res = await fetch('https://api.example.com/data', {
    cache: 'force-cache', // Static
    // cache: 'no-store', // Dynamic
    // next: { revalidate: 60 }, // ISR
  });
  return res.json();
}

export default async function Page() {
  const data = await getData();
  return <div>{data.title}</div>;
}

Improved Image Component

typescript
import Image from 'next/image';

// Automatic sizing
<Image
  src="/photo.jpg"
  alt="Photo"
  fill
  sizes="(max-width: 768px) 100vw, 50vw"
/>

Font Optimization

typescript
import { Inter } from 'next/font/google';

const inter = Inter({ subsets: ['latin'] });

export default function RootLayout({ children }) {
  return (
    <html lang="en" className={inter.className}>
      <body>{children}</body>
    </html>
  );
}

Migration Guide

Gradual Adoption

    The app directory coexists with pages:
  • Start new features in app/
  • Migrate existing routes gradually
  • Both work simultaneously

Key Changes

From getStaticProps/getServerSideProps

typescript
// Old (pages/)
export async function getStaticProps() {
  const data = await fetchData();
  return { props: { data } };
}

// New (app/)
async function getData() {
  return fetchData();
}

export default async function Page() {
  const data = await getData();
  return <div>{data}</div>;
}

From API Routes

typescript
// Old: pages/api/users.ts
// New: app/api/users/route.ts

export async function GET(request: Request) {
  return Response.json({ users: [] });
}

export async function POST(request: Request) {
  const body = await request.json();
  return Response.json({ created: body });
}

Migration Checklist

  • 1. Update Next.js version
  • 2. Create app/ directory
  • 3. Migrate layouts first
  • 4. Move routes gradually
  • 5. Update data fetching
  • 6. Test thoroughly
  • Best Practices

    When to Use Server vs Client

      Server Components
    • Data fetching
    • Backend access
    • Static content
    • SEO-critical content
      Client Components
    • Interactivity
    • Browser APIs
    • State management
    • Event handlers

    Performance Tips

  • Minimize client components
  • Use streaming for slow data
  • Leverage caching
  • Optimize images
  • Conclusion

    "Next.js 13's server components fundamentally change how we think about React applications. The performance gains are substantial."
    — Hrishikesh Baidya, Lead Developer

    Next.js 13 offers significant improvements in performance and developer experience. Plan your migration carefully and adopt features gradually. We've built projects like TalkDrill and AppliedView using modern Next.js patterns.

    Need Help with Next.js Development?

    Our web development team specializes in building high-performance Next.js applications with server components and optimal caching strategies.

    Start Your Project
    Tags:
    Next.jsReactJavaScriptWeb DevelopmentFrontend
    Share this post:
    Hrishikesh Baidya

    Hrishikesh Baidya

    CTO at Softechinfra specializing in Python, system architecture, and building secure, scalable software solutions.