How Modern Next.js Actually Works and Interview Guide

I am a javascript developer from Bangladesh. I love to work with javascript modern frameworks and libraries. Although I have a sour and sweet relationship with programming.π₯Ί
Modern App Router + React Server Components + RSC Payload + Bundling + Hydration + Streaming + Prefetching Deep Dive
π How To Read These Notes
These notes are structured in:
π§ Mental models first
βοΈ Internal architecture second
π Step-by-step flows third
π― Interview understanding last
Every section contains:
Core concept
Internal flow
Runtime behavior
Mental picture
Interview questions
Goal:
After reading these notes,
you should be able to:
- visualize the full Next.js lifecycle
- explain modern architecture clearly
- answer interview questions confidently
- understand WHY Next.js is fast
π₯ MOST IMPORTANT MODERN NEXT.JS UNDERSTANDING
Server Components
β
Generate HTML + RSC payload
Client Components
β
Generate browser JS bundles + hydration
This is the core architecture shift from old React SPA systems.
π¨ COMMON BEGINNER CONFUSIONS
| Confusion | Correct Understanding |
|---|---|
| βuse clientβ means CSR | β Wrong |
| Server Components create browser bundles | β Usually wrong |
| Hydration creates HTML | β Wrong |
| Browser runs Server Components | β Wrong |
| HTML appears after JS download | β Wrong |
β CORRECT MODERN FLOW
Server executes Server Components
β
Generate HTML + RSC payload
β
Browser paints HTML immediately
β
Browser downloads Client Component JS
β
Hydration activates interactivity
Complete Modern Next.js Mental Model & Interview Guide
Table of Contents
What is Next.js Really?
High-Level Architecture
Build Phase Internals
Dependency Graph & Bundling
Route-Based Code Splitting
Tree Shaking
Webpack vs Turbopack
Rendering Strategies (SSR, SSG, ISR, CSR)
Modern Next.js Architecture
Server Components vs Client Components
Hydration
React Server Component (RSC) Payload
Streaming Architecture
Full Request Lifecycle
Prefetching System
End-to-End Browser Navigation Flow
Modern Mental Models
Most Important Interview Questions
1. What is Next.js Really?
Most developers think Next.js is only:
React framework
But internally, modern Next.js is much bigger.
Real Mental Model
Next.js is:
A compiler
+ bundler
+ router
+ rendering engine
+ caching system
+ server framework
+ React orchestration layer
Its job:
1. Analyze your app
2. Split server/client code
3. Create optimized bundles
4. Render HTML efficiently
5. Send minimal JavaScript
6. Hydrate interactivity
7. Cache aggressively
8. Stream UI efficiently
Ultimate Big Picture
Developer writes React app
β
Next.js analyzes app
β
Creates dependency graph
β
Separates server/client code
β
Creates optimized chunks
β
Handles requests
β
Fetches data
β
Renders React
β
Generates HTML + RSC payload
β
Sends minimal JS
β
Browser hydrates app
β
Fast interactive website
Interview Questions
Q: What is Next.js internally?
Answer:
Next.js is a full-stack React framework that combines routing, rendering, bundling, server execution, caching, and streaming into a unified architecture.
Q: Why is Next.js faster than plain React SPA?
Answer:
Because it supports:
Server rendering
Static generation
Route-based code splitting
Streaming
Server Components
Smart caching
Prefetching
Optimized bundling
2. High-Level Architecture
Modern Next.js has TWO worlds.
| World | Runs Where | Purpose |
|---|---|---|
| Server World | Node.js / Edge | Data fetching, DB access, rendering |
| Client World | Browser | Interactivity |
Core Understanding
Next.js automatically decides:
What runs on server?
What runs in browser?
What should be bundled?
What should stay private?
Internal Architecture Flow
SERVER SIDE
--------------------------------
Routing
Data Fetching
DB Queries
Server Components
HTML Generation
RSC Payload Generation
Caching
Streaming
CLIENT SIDE
--------------------------------
Render HTML
Download JS bundles
Hydration
Client Navigation
State Updates
Interactive UI
Most Important Understanding
Browser should NOT receive:
database queries
secrets
Prisma code
server utilities
Browser SHOULD receive:
HTML
minimal JS
client component bundles
RSC payload
Interview Questions
Q: What are the two execution environments in Next.js?
Answer:
The server environment handles rendering, data fetching, and secure logic, while the client environment handles browser interactivity and hydration.
Q: Why are Server Components important?
Answer:
Because they:
Reduce browser JavaScript
improve performance
keep secrets secure
allow direct DB access
reduce hydration cost
3. Build Phase Internals
When you run:
npm run build
Next.js starts analyzing your app.
Build Pipeline
Read Files
β
Analyze Imports
β
Create Dependency Graph
β
Detect Routes
β
Separate Server/Client Code
β
Create Bundles
β
Generate Static Pages
β
Create Server Runtime
STEP 1 β File System Scanning
Next.js scans:
app/
pages/
Example:
app/about/page.tsx
becomes:
/about
STEP 2 β Dependency Analysis
Next.js analyzes imports:
page.tsx
βββ Header.tsx
βββ Navbar.tsx
Creates graph:
Page
βββ Header
βββ Navbar
This graph powers:
bundle splitting
tree shaking (Removing unused code from the final bundle)
shared chunks
route optimization
STEP 3 β Server vs Client Separation
Next.js checks:
"use client"
Flow:
All Components
β
Check "use client"
β
Server Bucket Client Bucket
STEP 4 β Bundle Generation
Bundler creates optimized chunks.
Example:
home.bundle.js
dashboard.bundle.js
vendor.bundle.js
STEP 5 β Static Optimization
Next.js asks:
Can this page be pre-rendered?
If YES:
Generate static HTML during build
Build Output
Generated inside:
.next/
Contains:
server/
static/
chunks/
cache/
Interview Questions
Q: What happens during Next.js build?
Answer:
Next.js scans routes, analyzes dependencies, separates server/client components, creates optimized bundles, generates static assets, and prepares the server runtime.
Q: What is dependency graph analysis?
Answer:
The bundler builds a graph of module relationships to understand which files depend on each other. This enables code splitting, tree shaking, and shared chunk extraction.
4. Dependency Graph & Bundling
This is one of the MOST important concepts.
Bundlers do NOT think in pages.
They think in:
Dependency Graphs
Routes are entry points into the graph.
Example
Dashboard Page
βββ Navbar
βββ Chart
βββ Table
Another route:
About Page
βββ Navbar
βββ Team
Bundler detects:
Navbar shared across routes
Shared Chunk Extraction
Instead of duplicating:
Navbar copied everywhere
Bundler creates:
shared-navbar.chunk.js
Final Output
shared.chunk.js
about.chunk.js
dashboard.chunk.js
vendor-react.chunk.js
Why This Matters
Benefits:
smaller downloads
browser cache reuse
faster navigation
less duplication
Browser Request Flow
User visits:
/dashboard
Next.js checks route manifest:
/dashboard requires:
- shared.chunk.js
- dashboard.chunk.js
Only those bundles sent.
Mental Model
Each route gets:
β
Minimal route-specific JS
β
Plus shared chunks
β
Plus dynamic chunks if needed
Interview Questions
Q: Does Next.js bundle per page?
Answer:
Yes. Next.js performs route-based code splitting. Each route gets optimized bundles while shared dependencies are extracted into shared chunks.
Q: Why are shared chunks useful?
Answer:
Shared chunks avoid duplication across routes and allow browsers to reuse cached JavaScript.
5. Route-Based Code Splitting
Modern Next.js automatically performs:
Route-level splitting
+ Component-level splitting
+ Dynamic import splitting
+ RSC payload splitting
Example
app/
βββ page.tsx
βββ about/page.tsx
βββ dashboard/page.tsx
Possible output:
home.bundle.js
about.bundle.js
dashboard.bundle.js
Dynamic Import Splitting
import dynamic from "next/dynamic";
const Chart = dynamic(() => import("./Chart"));
Now:
Chart code loads only when needed
Why Dynamic Splitting Matters
Without splitting:
Download all dashboard code immediately
With dynamic splitting:
Load heavy components lazily
Useful for:
charts
editors
maps
large dashboards
Route Splitting Flow
Route Files
β
Dependency Analysis
β
Shared Dependency Detection
β
Chunk Generation
β
Manifest Creation
β
Browser loads required chunks only
Interview Questions
Q: What is code splitting?
Answer:
Code splitting breaks the application into smaller bundles so users only download the JavaScript needed for the current route or feature.
Q: What is dynamic import?
Answer:
Dynamic import lazily loads modules at runtime and creates separate chunks that load only when required.
6. Tree Shaking
Tree shaking removes unused code.
Example
import { add, subtract } from "./math";
If only:
add()
is used:
subtract removed from final bundle
Why Tree Shaking Important
Without it:
Unused code ships to browser
With it:
Smaller bundles
Faster downloads
Better performance
Interview Questions
Q: What is tree shaking?
Answer:
Tree shaking is the process of removing unused exports from the final bundle during build optimization.
7. Webpack vs Turbopack
Both are bundlers.
Their job:
Source Code
β
Analyze Dependencies
β
Bundle/Split/Optimize
β
Generate Browser-Ready Assets
Why Webpack Became Slow
Modern apps contain:
thousands of modules
TypeScript
monorepos
huge dependency graphs
server/client splitting
advanced HMR
Webpack struggles with repeated rebuilds.
Webpack Flow
File Change
β
Re-analyze graph
β
Rebuild many modules
β
Update browser
Turbopack Architecture
Built with:
Rust
incremental computation
fine-grained invalidation
parallel execution
Turbopack Core Idea
Recompute ONLY what changed
Example
Edit:
Chart.tsx
Webpack may rebuild:
Chart
Dashboard
Shared chunks
Dependencies
Turbopack tries:
Only Chart-related graph updates
Major Differences
| Feature | Webpack | Turbopack |
|---|---|---|
| Language | JavaScript | Rust |
| Incremental Engine | Limited | Advanced |
| HMR | Good | Extremely Fast |
| Large Apps | Heavy | Optimized |
| Parallelism | Limited | Better |
| Modern RSC Support | Older Architecture | Native-first |
Development Experience
Webpack
Save file
Wait seconds
Browser updates
Turbopack
Save file
Almost instant update
Production Reality
| Area | Status |
|---|---|
| Development | Turbopack Excellent |
| Production Builds | Webpack still widely stable |
What Should You Use?
Development:
next dev --turbopack
especially for:
large apps
monorepos
TypeScript
Important Understanding
Neither Webpack nor Turbopack runs in browser.
They are:
Build-time and development-time tools
Their output becomes:
Optimized JS/CSS bundles
Interview Questions
Q: Why is Turbopack faster?
Answer:
Turbopack uses incremental computation, fine-grained dependency tracking, Rust-based performance, and smarter invalidation to recompute only the changed parts of the dependency graph.
Q: What is the biggest conceptual shift from Webpack to Turbopack?
Answer:
Webpack is rebuild-oriented while Turbopack is incremental and reactive.
8. Rendering Strategies (SSR, SSG, ISR, CSR)
This is a foundational interview topic.
Important Modern Understanding
Modern Next.js still uses:
SSR
SSG
ISR
CSR
BUT modern architecture is now component-driven.
Rendering Strategy Table
| Strategy | Meaning |
|---|---|
| SSR | Render per request |
| SSG | Build-time render |
| ISR | Regenerated cached render |
| CSR | Browser rendering |
SSR β Server Side Rendering
HTML generated on every request.
Flow:
Request
β
Server renders React
β
HTML generated
β
Browser receives page
Example
export default async function Page() {
const users = await fetch(...)
}
SSR Pros
SEO friendly
fresh data
secure
personalized content
SSR Cons
more server work
slower than static
SSG β Static Site Generation
Generated during build.
Flow:
Build
β
HTML generated
β
CDN serves static file
Perfect for:
blogs
docs
landing pages
ISR β Incremental Static Regeneration
Hybrid model.
export const revalidate = 60;
Meaning:
Regenerate every 60 seconds
Flow:
Request
β
Serve cached HTML
β
Background regeneration
CSR β Client Side Rendering
Browser downloads JS first.
Flow:
HTML shell
β
Download JS
β
React renders in browser
Useful for:
interactive dashboards
charts
highly dynamic UI
Important Modern Mapping
| Modern Behavior | Old Concept |
|---|---|
| Dynamic rendering | SSR |
| Static prerender | SSG |
| Revalidation | ISR |
| Browser rendering | CSR |
Interview Questions
Q: Difference between SSR and CSR?
Answer:
SSR renders HTML on the server before sending it to the browser, while CSR renders the UI inside the browser after JavaScript loads.
Q: When should ISR be used?
Answer:
ISR is ideal for pages that need mostly static performance but require periodic data freshness.
9. Modern Next.js Architecture
Old Mental Model (Pages Router Era)
Focus:
SSR
SSG
ISR
CSR
Using:
getServerSideProps
getStaticProps
Modern Mental Model (App Router Era)
Focus:
Server Components
Client Components
Streaming
RSC Payload
Caching
Biggest Shift
Old Next.js:
Page-level rendering
Modern Next.js:
Component-level architecture
Modern Granular Rendering
Inside same page:
Some parts server-rendered
Some parts client-rendered
Some streamed
Some cached
Example
<Page>
<ServerRenderedProducts />
<ClientCart />
<StreamingReviews />
</Page>
Important Understanding
"use client"
DOES NOT mean:
Entire page rendered in browser
It only means:
This component requires browser JavaScript
Interview Questions
Q: What changed in modern Next.js?
Answer:
Modern Next.js moved from page-level rendering architecture to component-level server/client architecture with streaming and React Server Components.
10. Server Components vs Client Components
This is now the MOST important architectural concept.
Server Components
Default behavior.
Example:
export default async function Page() {}
Characteristics
run on server
not shipped to browser
direct DB access
smaller bundles
secure
Client Components
"use client";
Characteristics:
bundled for browser
interactive
supports useState/useEffect
hydrated in browser
Comparison Table
| Feature | Server Component | Client Component |
|---|---|---|
| Runs on server | YES | NO |
| Runs in browser | NO | YES |
| Access DB | YES | NO |
| useState | NO | YES |
| Browser bundle | Usually no | YES |
Internal Flow
Server Components
β
Rendered on server
β
Generate HTML/RSC payload
Client Components
β
Bundled for browser
β
Hydrated later
Most Important Modern Understanding
Modern React is becoming:
Server-first architecture
instead of:
Browser-first SPA architecture
Interview Questions
Q: Why are Server Components powerful?
Answer:
They reduce client JavaScript, improve performance, keep sensitive logic secure, and allow direct server-side data access.
Q: What does βuse clientβ actually do?
Answer:
It marks a component as client-side interactive code that must be bundled and hydrated in the browser.
11. Hydration
One of the MOST asked interview topics.
What is Hydration?
Hydration means:
React attaching interactivity to static HTML
Example
Server sends:
<button>Like</button>
Initially:
Visible but non-interactive
After JS loads:
React attaches click handlers
Now interactive.
Hydration Flow
Server HTML
β
Browser displays immediately
β
Download JS bundles
β
React hydrates components
β
Interactive application
Why Hydration Exists
HTML alone:
cannot manage state
cannot handle events
cannot update dynamically
Hydration connects:
event listeners
React state
browser behavior
Important Understanding
Hydration does NOT generate UI.
The UI already exists from server HTML.
Hydration adds:
Behavior + React runtime connectivity
Interview Questions
Q: What is hydration?
Answer:
Hydration is the process where React attaches JavaScript behavior and event handling to server-rendered HTML.
Q: Why is hydration needed?
Answer:
Because static HTML alone cannot support interactivity, state updates, or React event handling.
12. React Server Component (RSC) Payload
This is the MOST important modern React/Next.js topic.
The Problem RSC Solves
Old SPA architecture:
Download huge JS
β
Run React entirely in browser
β
Render UI
Problems:
large bundles
slower initial load
poor scalability
browser-heavy rendering
Core RSC Idea
Some components run ONLY on server
Browser receives:
final HTML
lightweight instructions
instead of full app logic.
Modern Response Structure
Modern Next.js sends:
1. HTML
2. RSC Payload
3. Client JS bundles
What HTML Does
Immediate screen paint
What RSC Payload Does
Helps React:
reconstruct component tree
identify client boundaries
hydrate correctly
handle navigation updates
Think of RSC Payload As
Serialized React component instructions
Example Architecture
<Page>
<ProductList />
<Cart />
</Page>
Suppose:
ProductList = Server Component
Cart = Client Component
Internal Flow
STEP 1 β Request Arrives
/products
STEP 2 β Server Executes Server Components
const products = await db.products.findMany()
Runs safely on server.
STEP 3 β React Builds Tree
Page
βββ ProductList (server)
βββ Cart (client)
STEP 4 β Generate HTML
Browser can paint immediately.
STEP 5 β Generate RSC Payload
Payload contains:
| Data | Purpose |
|---|---|
| component structure | rebuild tree |
| props | data transfer |
| client markers | hydration boundaries |
| module references | know JS requirements |
STEP 6 β Send Response
HTML
+
RSC payload
+
client bundles
STEP 7 β Browser Reads Payload
React reconstructs component tree.
STEP 8 β Hydration
Client components become interactive.
Full Visual Flow
SERVER
--------------------------------
Run Server Components
β
Fetch DB/API data
β
Generate HTML
β
Generate RSC Payload
β
Send response
BROWSER
--------------------------------
Render HTML immediately
β
Read RSC Payload
β
Rebuild component tree
β
Hydrate Client Components
β
Interactive UI
Why RSC Is Powerful
Without RSC:
Huge browser JS
With RSC:
Server does heavy work
Browser receives lightweight instructions
Benefits:
smaller bundles
faster loads
better scalability
secure server logic
less hydration cost
Extremely Important Understanding
HTML:
Shows UI
RSC payload:
Explains how UI was constructed
Navigation Optimization
Modern Next.js often fetches:
ONLY new RSC payload
instead of full page reload.
This enables:
instant transitions
partial rendering
streaming
Interview Questions
Q: What is the RSC payload?
Answer:
The RSC payload is a serialized representation of the React Server Component tree that helps the browser reconstruct the UI hierarchy and hydrate client components efficiently.
Q: Why is RSC architecture important?
Answer:
It significantly reduces browser JavaScript and shifts heavy rendering work back to the server.
13. Streaming Architecture
Streaming allows UI to arrive progressively.
Traditional Rendering
Wait entire page
β
Send full response
Streaming Rendering
Navbar first
Sidebar second
Content later
Reviews later
UI appears progressively.
Why Streaming Matters
Without streaming:
Slow API blocks entire page
With streaming:
Fast sections appear immediately
Slow sections arrive later
Streaming + Suspense
Streaming heavily works with:
React Suspense
Streaming + RSC
RSC payload itself can stream incrementally.
Example:
Navbar first
Products later
Reviews later
Interview Questions
Q: What is streaming in Next.js?
Answer:
Streaming allows the server to progressively send UI chunks to the browser instead of waiting for the entire page to finish rendering.
14. Full Request Lifecycle
This combines everything together.
Initial Request Lifecycle
User visits page
β
Request hits server
β
Next.js matches route
β
Fetch data
β
Render React tree
β
Generate HTML
β
Generate RSC payload
β
Send HTML + RSC + JS
β
Browser paints page
β
Download JS bundles
β
Hydration
β
Interactive app
Runtime Architecture
SERVER SIDE
--------------------------------
Route Match
Fetch Data
Render React
Generate HTML
Generate RSC Payload
Send Response
CLIENT SIDE
--------------------------------
Paint HTML
Download JS
Hydrate React
Interactive UI
Most Important Understanding
Modern Next.js tries to:
Move as much work as possible to the server
while minimizing browser JavaScript.
Interview Questions
Q: Explain the full lifecycle of a Next.js request.
Answer:
A request reaches the Next.js server, the route is matched, data is fetched, React renders the component tree on the server, HTML and the RSC payload are generated, the browser receives them, paints the HTML, downloads client bundles, and hydrates interactive components.
15. Prefetching System
One of the MOST important modern performance features.
The Problem Without Prefetching
Traditional navigation:
Click
β
Fetch route resources
β
Render
Delay happens AFTER click.
Core Prefetching Idea
Next.js predicts:
User may click this link soon
So it downloads resources BEFORE click.
Internal Flow
Render page
β
Observe visible <Link>
β
Link enters viewport
β
Schedule prefetch
β
Download route resources
β
Store in cache
How Visibility Detected
Using:
Intersection Observer
What Gets Prefetched?
Modern App Router may prefetch:
RSC payload
route metadata
loading boundaries
client JS chunks
Navigation After Prefetch
Click
β
Read prefetched cache
β
Update React tree
β
Instant render
WITHOUT PREFETCH
Click
β
DNS/TCP wait
β
Download route JS
β
Fetch data
β
Render
WITH PREFETCH
Before click:
Route resources cached
Click:
Immediate route transition
Automatic Prefetch
<Link href="/about" />
Disable Prefetch
<Link href="/about" prefetch={false} />
Useful for:
massive routes
mobile bandwidth
expensive pages
Advanced Mental Model
VISIBLE LINK
β
Intersection Observer detects visibility
β
Next.js prefetch scheduler runs
β
Fetch RSC payload + JS chunks
β
Store in router cache
β
User clicks
β
React merges prefetched server tree
β
Partial UI update without reload
Why Prefetching Powerful
Benefits:
near-instant navigation
app-like UX
lower perceived latency
smoother transitions
Downsides
bandwidth usage
memory usage
unused downloads
Interview Questions
Q: What is prefetching?
Answer:
Prefetching downloads future route resources before navigation so transitions become much faster.
Q: How does Next.js prefetch routes?
Answer:
Next.js observes visible Link components and automatically fetches route resources in the background using low-priority requests.
Q: What gets prefetched in App Router?
Answer:
App Router may prefetch React Server Component payloads, route metadata, loading boundaries, and required JavaScript chunks.
16. End-to-End Browser Navigation Flow
Initial Page Load
Browser requests route
β
Next.js server matches route
β
Fetch server data
β
Render React tree
β
Generate HTML + RSC payload
β
Send minimal JS bundles
β
Browser paints page
β
Hydration
β
Interactive UI
Client Navigation
User clicks <Link>
β
Check router cache
β
If prefetched β instant transition
β
If not β fetch route resources
β
Fetch new RSC payload
β
React merges updated tree
β
Partial UI update
Most Important Modern Understanding
Modern Next.js navigation is NOT:
Traditional full-page reload
It is:
Partial React tree replacement
using:
RSC payloads
router cache
client-side transitions
17. Modern Mental Models
Old React SPA Mental Model
Browser downloads app
β
Browser runs entire React app
β
Browser renders UI
Modern Next.js Mental Model
Server renders most UI
β
Browser receives HTML + instructions
β
Hydrate only interactive parts
Ultimate Next.js Brain Picture
Developer writes React app
β
Next.js analyzes dependency graph
β
Separates server/client components
β
Creates optimized chunks
β
Renders on server
β
Generates HTML + RSC payload
β
Streams response
β
Browser hydrates client components
β
Fast interactive application
Most Important Interview Understanding
Modern Next.js is:
Component-driven server-first architecture
where:
Server/Client Components determine execution environment
SSR/SSG/ISR/CSR determine rendering strategy
RSC payload enables efficient browser updates
Streaming improves perceived performance
Prefetching accelerates navigation
18. Most Important Interview Questions
Architecture
Q: What is the biggest architectural shift in modern Next.js?
The shift from page-level rendering architecture to component-level server/client rendering architecture.
Q: Why are React Server Components important?
They reduce browser JavaScript, improve scalability, keep server logic secure, and enable server-first rendering.
Rendering
Q: Difference between SSR and SSG?
SSR renders per request, while SSG pre-generates HTML during build time.
Q: What is ISR?
ISR combines static performance with periodic regeneration for fresh data.
Bundling
Q: How does route-based code splitting work?
The bundler analyzes the dependency graph for each route, extracts shared dependencies, and generates route-specific chunks loaded on demand.
Q: Why is Turbopack faster?
Because it uses incremental computation and fine-grained dependency invalidation instead of broad rebuilds.
Hydration
Q: What is hydration?
Hydration is React attaching JavaScript interactivity to already-rendered HTML.
RSC Payload
Q: What is the RSC payload?
A serialized representation of the server-rendered React component tree used by the browser to reconstruct and hydrate the UI efficiently.
Prefetching
Q: How does Next.js prefetch routes?
Next.js observes visible links and prefetches route resources in the background before navigation occurs.
Final One-Line Mental Model
Next.js is a server-first React architecture that intelligently splits execution between server and browser, streams HTML and RSC payloads efficiently, minimizes client JavaScript, and enables fast interactive navigation through caching, hydration, and prefetching.
FINAL MODERN NEXT.JS MENTAL MODEL
This is the most important complete mental picture.
OLD REACT SPA MENTAL MODEL
Browser downloads huge JS
β
React runs entirely in browser
β
Browser renders UI
β
Hydration everywhere
Problems:
huge JS bundles
slower initial load
browser-heavy rendering
poor scalability
MODERN NEXT.JS MENTAL MODEL
SERVER
--------------------------------
1. Request comes
β
2. Server executes Server Components
β
3. Fetch DB/API data
β
4. React renders component tree
β
5. Generate HTML
β
6. Generate RSC payload
β
7. Detect Client Components
β
8. Send:
- HTML
- RSC payload
- Client JS references
BROWSER
--------------------------------
9. Browser receives HTML
β
10. Browser paints UI immediately
β
11. Browser reads RSC payload
β
12. Browser downloads required JS bundles
β
13. React hydrates Client Components
β
14. Interactive UI becomes active
MOST IMPORTANT UNDERSTANDING
Server Components
Usually produce:
HTML + RSC payload
Usually DO NOT produce:
Browser JS bundles
Because they:
run only on server
are not hydrated
do not need browser runtime
Client Components
Produce:
Browser JS bundles
+ hydration
+ interactivity
because browser must:
attach event handlers
manage state
run React runtime
HYDRATION MENTAL MODEL
HTML appears first
β
JS downloads later
β
Hydration happens later
β
Interactive behavior activates
WHY MODERN NEXT.JS IS FAST
Because:
Less JavaScript shipped
β
More work moved to server
β
HTML visible immediately
β
Only interactive parts hydrated
MODERN ARCHITECTURE GOAL
Static/server UI
β
NO browser JS
Interactive UI
β
Only necessary JS
ULTIMATE BRAIN PICTURE
Developer writes React app
β
Next.js analyzes dependency graph
β
Separates Server/Client Components
β
Creates optimized chunks
β
Server renders React tree
β
Generates HTML + RSC payload
β
Browser paints HTML immediately
β
Downloads only required client JS
β
Hydrates interactive components
β
Fast modern web app
FINAL INTERVIEW UNDERSTANDING
Modern Next.js is:
A server-first, component-driven React architecture
where:
Server Components execute on the server
Client Components execute in the browser
RSC payload connects server and browser React trees
HTML is streamed early for fast paint
Hydration activates interactivity later
Only the necessary JavaScript is shipped to the browser
π₯ COMPLETE END-TO-END FLOW
==================================================
BUILD PHASE
==================================================
Developer writes React app
β
Next.js scans app/ routes
β
Analyze imports
β
Create dependency graph
β
Detect Server vs Client Components
β
Create optimized chunks/bundles
β
Extract shared chunks
β
Tree shaking removes unused code
β
Generate static pages if possible
β
Prepare server runtime
==================================================
REQUEST PHASE
==================================================
Browser requests page
β
Request reaches Next.js server
β
Route matched
β
Server executes Server Components
β
Fetch DB/API data
β
React renders component tree
β
Generate HTML
β
Generate RSC payload
β
Detect Client Components
β
Send:
- HTML
- RSC payload
- Client JS references
==================================================
BROWSER PHASE
==================================================
Browser receives HTML
β
Browser paints UI IMMEDIATELY
β
Browser reads RSC payload
β
Browser downloads required JS bundles
β
React hydrates Client Components
β
Interactive UI becomes active
==================================================
NAVIGATION PHASE
==================================================
User clicks <Link>
β
Check router cache
β
If prefetched:
instant navigation
Else:
fetch route resources
β
Fetch new RSC payload
β
React merges updated tree
β
Partial UI update
β
No full page reload
==================================================
PREFETCH FLOW
==================================================
Link enters viewport
β
Next.js predicts future navigation
β
Prefetch:
- RSC payload
- route metadata
- JS chunks
β
Store in router cache
β
Later click becomes instant
==================================================
HYDRATION FLOW
==================================================
HTML appears FIRST
β
JS downloads LATER
β
Hydration happens LATER
β
Interactive behavior activates





