Skip to content

Latest commit

Β 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Next.js Streaming Demo

A modern, production-ready Next.js application demonstrating server-side streaming with React Suspense, showcasing popular web frameworks and development tools.

Next.js React Tailwind CSS License

πŸš€ Features

Core Functionality

  • ⚑ Server-Side Streaming - Leverages Next.js 15+ streaming with Suspense boundaries for optimal performance
  • 🎯 Framework Showcase - Displays 9 popular frameworks (React, Vue, Angular, Svelte, Preact, Angular, Astro, Flutter, Solid)
  • πŸ’Ύ Persistent Likes - Save your favorite frameworks to browser storage with instant visual feedback
  • 🎨 Modern UI - Built with shadcn/ui and Tailwind CSS for a polished, responsive design
  • β™Ώ Accessible - Full ARIA support, keyboard navigation, and semantic HTML
  • πŸ”’ Type Safe - JavaScript with clear component structure and error handling

Performance Optimizations

  • Memoized components to prevent unnecessary re-renders
  • Optimized key props for stable React rendering
  • Centralized icon data storage for reduced memory usage
  • Image optimization with AVIF and WebP formats
  • Automatic code splitting and lazy loading with Suspense

User Experience

  • Optimistic Updates - Like buttons provide instant feedback using React's useOptimistic hook
  • Error Boundaries - Graceful error handling with recovery options
  • Skeleton Loaders - Beautiful loading states while content streams in
  • SEO Optimized - Rich metadata, proper heading hierarchy, and schema markup support

πŸ› οΈ Tech Stack

Technology Version Purpose
Next.js 15.4.4 React framework with streaming support
React 19.1.0 UI library
Tailwind CSS 4 Utility-first CSS framework
Lucide React 0.525.0 Icon library
Radix UI 1.2.3 Accessible component primitives

πŸ“‹ Prerequisites

  • Node.js 18.0 or higher
  • npm 9.0+ or yarn 4.0+

πŸš€ Getting Started

Installation

# Clone the repository
git clone https://github.com/Antonynans/Next.js-streaming-demo.git
cd nextjs-streaming

# Install dependencies
npm install
# or
yarn install

Development

# Start development server with Turbopack
npm run dev

The application will be available at http://localhost:3000 (or the next available port if 3000 is in use).

Production Build

# Build for production
npm run build

# Start production server
npm start

Linting

# Run ESLint
npm run lint

πŸ“ Project Structure

nextjs-streaming/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ globals.css              # Global styles
β”‚   β”œβ”€β”€ layout.js                # Root layout with metadata
β”‚   β”œβ”€β”€ page.js                  # Home page
β”‚   └── streaming-demo/
β”‚       └── page.js              # Streaming demo page
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ error-boundary.js        # Error handling component
β”‚   β”œβ”€β”€ icon-card.js             # Individual tool card
β”‚   β”œβ”€β”€ icon-component.js        # Icon renderer
β”‚   β”œβ”€β”€ like-button.js           # Like button with persistence
β”‚   β”œβ”€β”€ tools-cards.js           # Main tools container
β”‚   β”œβ”€β”€ tools-cards-view.js      # Client-side tools view
β”‚   β”œβ”€β”€ tools-cards-wrapper.js   # Filter wrapper
β”‚   β”œβ”€β”€ tools-filter.js          # Search and sort UI
β”‚   └── ui/                      # shadcn/ui components
β”‚       β”œβ”€β”€ button.jsx
β”‚       β”œβ”€β”€ card.jsx
β”‚       β”œβ”€β”€ card-skeleton.jsx
β”‚       └── skeleton.jsx
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ getTools.js              # Server action for fetching tools
β”‚   β”œβ”€β”€ icons-data.js            # Centralized icon definitions
β”‚   └── utils.js                 # Utility functions
β”œβ”€β”€ next.config.mjs              # Next.js configuration
β”œβ”€β”€ postcss.config.mjs           # PostCSS configuration
β”œβ”€β”€ tailwind.config.js           # Tailwind CSS configuration
└── package.json                 # Dependencies and scripts

🎯 Key Components

ToolsCards (Server Component)

The main entry point that:

  • Fetches tools data server-side using a server action
  • Wraps individual cards with Suspense boundaries
  • Handles errors gracefully
  • Displays skeleton loaders while streaming
// Components render individually as they stream in
<Suspense fallback={<CardSkeleton />}>
  <ToolsCard toolPromise={toolPromise} />
</Suspense>

LikeButton (Client Component)

Demonstrates advanced React patterns:

  • Uses useOptimistic for instant UI feedback
  • Persists data to localStorage
  • Handles hydration safely with useEffect
  • Provides proper ARIA labels

IconComponent

Renders framework icons from centralized data store, enabling:

  • Better code organization
  • Reduced memory usage
  • Easy maintenance and updates

🌟 Advanced Features

Server-Side Rendering with Streaming

The application uses Next.js 15+ streaming capabilities to progressively render content:

  1. Server Components render on the server
  2. Suspense Boundaries stream content as it's ready
  3. Fallback UI shows skeleton loaders
  4. Client Interactivity works immediately on hydration

Optimistic Updates

The like button demonstrates React 19's useOptimistic hook:

const [optimisticLiked, addOptimisticLike] = useOptimistic(false);

// Immediate UI update while server processes
addOptimisticLike(!optimisticLiked);

// Server updates localStorage in background
await toggleLike(toolId, optimisticLiked);

Error Handling

Multiple layers of error handling:

  • Server-side validation in getTools()
  • Error boundary component for React errors
  • Graceful fallbacks for missing data
  • User-friendly error messages

πŸ“Š Performance Features

  • Code Splitting: Automatic chunking of JavaScript
  • Lazy Loading: Components load on-demand with Suspense
  • Image Optimization: Configured AVIF and WebP formats
  • Memoization: Prevents unnecessary re-renders with React.memo
  • Hydration Safety: Proper hydration handling for client/server mismatches

β™Ώ Accessibility

  • ARIA Labels: All interactive elements have proper labels
  • Keyboard Navigation: Full keyboard support
  • Semantic HTML: Proper heading hierarchy and structure
  • Screen Reader Support: Enhanced with descriptive labels
  • Color Contrast: WCAG AA compliant

πŸ”’ Security

  • Security Headers: X-UA-Compatible and X-Content-Type-Options configured
  • Content Security: Protected against XSS attacks
  • Input Validation: Server-side validation of all data
  • Secure Defaults: Safe configuration in next.config.mjs

πŸ“± Browser Support

  • Chrome/Edge 90+
  • Firefox 88+
  • Safari 14+
  • Mobile browsers (iOS Safari, Chrome Mobile)

πŸ§ͺ Testing

# Run linter
npm run lint

# Build for production (validates entire app)
npm run build

πŸ“ Environment Variables

Currently, no environment variables are required. The app uses:

  • NEXT_PUBLIC_* - Client-side accessible variables (none currently)
  • Server-side only variables - None configured

To add environment variables, create .env.local:

# Example (if needed in future)
NEXT_PUBLIC_API_URL=https://api.example.com

πŸš€ Deployment

Vercel (Recommended)

# Deploy to Vercel (connected GitHub repo)
vercel

Docker

# Build Docker image
docker build -t nextjs-streaming .

# Run container
docker run -p 3000:3000 nextjs-streaming

Other Platforms

The app works on any platform supporting Node.js 18+:

  • Netlify
  • AWS Amplify
  • Railway
  • Render
  • DigitalOcean

πŸ“š Learning Resources

Concepts Demonstrated

  1. Server Components - Render on server, zero JavaScript cost
  2. Suspense & Streaming - Progressive enhancement of UI
  3. useOptimistic - React 19 feature for optimistic updates
  4. Error Boundaries - Graceful error handling
  5. Client vs Server - Clear separation of concerns
  6. Performance Optimization - Memoization and code splitting

Documentation

πŸ“‹ Available Scripts

npm run dev          # Start development server with Turbopack
npm run build        # Build for production
npm start            # Start production server
npm run lint         # Run ESLint on codebase

πŸ”„ State Management

The app demonstrates different state management approaches:

  1. Server State - Fetched via server actions in getTools.js
  2. Client State - localStorage for likes persistence
  3. Optimistic State - Instant UI feedback with useOptimistic
  4. React State - Local component state for UI interactions

🎨 Customization

Adding New Frameworks

Edit lib/getTools.js:

const TOOLS = [
  "JavaScript",
  "React",
  // Add your framework here
  "MyFramework",
];

Adding Framework Icons

Edit lib/icons-data.js and add a new object to the ICONS array:

{
    id: "MyFramework",
    icon: (
        <svg>
            {/* Your SVG here */}
        </svg>
    ),
}

Styling

  • Global styles: app/globals.css
  • Component styles: Inline with Tailwind classes
  • Configuration: tailwind.config.js

πŸ› Troubleshooting

Port Already in Use

# Change port
npm run dev -- -p 3001

Build Failures

# Clear Next.js cache
rm -rf .next

# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install

# Build again
npm run build

Hydration Mismatch

The app includes hydration safety checks. If you see hydration warnings:

  1. Check for date/time differences between server and client
  2. Verify useEffect is used for client-only code
  3. Ensure Suspense boundaries wrap dynamic content

🀝 Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“ž Support

For issues, questions, or suggestions:

  1. Check the GitHub Issues
  2. Review the Next.js Documentation
  3. Visit the React Documentation

πŸ—ΊοΈ Roadmap

  • Add search and filtering functionality
  • Implement sorting options (A-Z, popularity)
  • Add backend API for persistent storage
  • Database integration for likes
  • Analytics tracking
  • Dark/Light mode toggle
  • Multi-language support
  • PWA support

Made with ❀️ using Next.js 15

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages