The Problem React Alone Has, CSR and the Blank Screen
Exploring the problem react alone has, csr and the blank screen and common implementation patterns
1. The Problem
React ships JavaScript to the browser. The browser downloads it, parses it, executes it, and then renders the UI. Until all three of those steps complete, the user sees nothing. A blank white screen.
For a small application on a fast connection, this gap is imperceptible. For a real application with a meaningful JavaScript bundle on a mid-range device in India on a 4G connection, this gap is 3 to 8 seconds. The user stares at a blank screen, assumes the site is broken, and leaves.
But the blank screen is only half the problem. The other half is invisible: search engines and social media crawlers request your page, receive an HTML file that contains almost no content (just a <div id="root"></div> and a <script> tag), and either cannot index your content or index it incorrectly. A React application built without Next.js is effectively invisible to Google until the crawler executes JavaScript, which not all crawlers do and none do as reliably as reading static HTML.
These two problems, user-perceived performance and discoverability, are what Next.js fundamentally solves. Every rendering strategy in Next.js is a different answer to the same question: when and where should the HTML that the user first sees be generated?
2. The Naive Attempt
A pure React application (Create React App, Vite with React, any client-only setup) works like this:
User requests https://myapp.com/products
Server responds with:
─────────────────────────────────────────
<!DOCTYPE html>
<html>
<head>
<title>My App</title>
</head>
<body>
<div id="root"></div>
<script src="/static/js/main.abc123.js"></script>
</body>
</html>
─────────────────────────────────────────
Browser receives this HTML.
Parses it: finds a div and a script tag.
Renders: blank screen with an empty div.
Downloads main.abc123.js (2MB bundle).
Parses and executes the JavaScript.
React mounts, calls your components.
Data fetches begin (useEffect fires).
Data arrives.
React re-renders with data.
User finally sees the product list.
Every step after “blank screen” is work the browser must do before the user sees anything meaningful. This is Client-Side Rendering (CSR): all rendering happens in the browser, driven by JavaScript.
The full timeline for a typical CSR application on a mid-range device:
0ms → Request sent
200ms → HTML received (the empty shell)
200ms → Browser starts parsing HTML
250ms → Script tag found, JS download begins
1800ms → JS bundle downloaded (2MB on 3G)
2100ms → JS parsed and executed
2100ms → React mounts, useEffect fires
2100ms → API request begins
2800ms → API response received
2800ms → React re-renders with data
2800ms → User sees meaningful content
First Contentful Paint (FCP): 2100ms (the React shell, still no real content). Time to Meaningful Content: 2800ms.
For context: Google’s Core Web Vitals consider anything above 2.5s for Largest Contentful Paint (LCP) as “needs improvement.” Most CSR React applications fail this threshold by default.
3. Why That Breaks
Three distinct failure modes.
Failure mode 1: The bundle must be downloaded before anything renders.
CSR requires the JavaScript bundle before any rendering can begin. The bundle includes React itself, your application code, your component tree, and usually a significant chunk of your dependencies. There is no way to show the user anything without it. The bundle size is a hard dependency on first meaningful paint.
Failure mode 2: Data fetching cannot begin until React mounts.
In a CSR application, data fetching lives in useEffect. useEffect runs after the component mounts. Components mount after JavaScript executes. JavaScript executes after the bundle downloads. So the data fetch, which is often the slowest part of the page load, cannot even begin until the entire bundle has been downloaded, parsed, and executed. This is a request waterfall baked into the architecture.
Download bundle → Execute JS → Mount components → useEffect fires → Fetch data → Render
↑
Cannot start here ──────────────────────────────
Failure mode 3: Search engines receive empty HTML.
When Googlebot requests /products, it receives the empty shell HTML. Googlebot does execute JavaScript, but it does so in a separate crawl queue that can take days or weeks. The initial crawl returns no content. Your product pages are either not indexed or indexed with no content. Competitors with server-rendered pages rank higher because their HTML contains the actual content on the first request.
4. Next.js’s Mental Model
The blank screen and the SEO problem both have the same root cause: HTML content is generated in the browser, after JavaScript runs, instead of on the server, before the user receives anything.
Next.js moves HTML generation to the server. Not the client’s browser. A real server (or build process) that has access to your data, your components, and your rendering logic. When the user requests a page, they receive HTML that already contains the rendered content. The browser displays it immediately. JavaScript arrives later and React “hydrates” the existing HTML, attaching event listeners and making it interactive. But the user sees content before any of that happens.
One sentence: Next.js generates HTML on the server so the browser has something to display before JavaScript runs, eliminating the blank screen and giving search engines real content to index.
5. What Next.js Does
Next.js intercepts the request-response cycle. Instead of a server that just serves static files (the CSR model), Next.js runs a Node.js server (or edge runtime) that can execute your React components and produce HTML before sending a response.
The same request to https://myapp.com/products:
User requests https://myapp.com/products
Next.js server:
1. Receives the request
2. Runs your React component tree on the server
3. Fetches the product data (on the server, not in useEffect)
4. Renders the components to HTML strings
5. Sends complete HTML to the browser
Browser receives:
─────────────────────────────────────────
<!DOCTYPE html>
<html>
<head><title>Products</title></head>
<body>
<div id="root">
<div class="product-list">
<div class="product-card">
<h2>Product A</h2>
<p>$29.99</p>
</div>
<div class="product-card">
<h2>Product B</h2>
<p>$49.99</p>
</div>
<!-- actual content, not empty div -->
</div>
</div>
<script src="/_next/static/chunks/main.js"></script>
</body>
</html>
─────────────────────────────────────────
Browser receives HTML with actual content.
Displays it immediately: user sees products.
JavaScript downloads in the background.
React hydrates: attaches event handlers.
Page becomes fully interactive.
The timeline:
0ms → Request sent
200ms → Server receives request
400ms → Server fetches data, renders HTML
600ms → Complete HTML received by browser
600ms → Browser displays product list ← user sees content here
800ms → JS bundle begins downloading
2000ms → JS downloaded, React hydrates
2000ms → Page fully interactive
Time to Meaningful Content: 600ms instead of 2800ms.
Hydration: what it is and why it is necessary.
The HTML the server sends is static. It looks correct but clicking buttons does nothing. JavaScript has not run yet. React’s event handlers have not been attached. The product “Add to cart” button is visually present but inert.
Hydration is the process of React running in the browser, examining the existing server-rendered HTML, matching it against the component tree, and attaching event listeners and state to the existing DOM nodes without destroying and recreating them.
Server HTML (static, displayed immediately):
<button class="add-to-cart">Add to cart</button>
After hydration (interactive):
<button class="add-to-cart" onClick={handleAddToCart}>Add to cart</button>
React does not re-render the HTML during hydration. It walks the existing DOM, confirms it matches what the component tree would produce, and attaches the JavaScript behavior. If the server HTML matches the client render exactly, hydration is silent. If they differ (a “hydration mismatch”), React must correct the DOM, which can produce a flash of incorrect content.
The three questions that determine which Next.js strategy to use.
CSR is appropriate when: the page is behind authentication, SEO does not matter, the page is heavily interactive and dynamic (dashboards, admin panels).
Server rendering becomes necessary when: the page needs to be indexed by search engines, the first meaningful paint performance matters to users, or the data must be fresh from the server on every request.
The specific flavor of server rendering (SSR, SSG, ISR, RSC) depends on how frequently the data changes and whether the HTML can be prepared in advance. We cover this in 1.2 and beyond.
6. Internals
How Next.js renders React to HTML on the server.
Next.js uses React’s server rendering APIs. In the Pages Router era, this was ReactDOMServer.renderToString(). In the App Router era with React Server Components, this is React’s streaming server renderer (renderToPipeableStream or renderToReadableStream).
// Simplified: what Next.js does under the hood for each request
import { renderToPipeableStream } from 'react-dom/server';
async function handleRequest(req, res) {
const url = req.url;
const Component = getComponentForRoute(url);
const data = await fetchDataForRoute(url);
const { pipe } = renderToPipeableStream(<Component data={data} />, {
onShellReady() {
res.setHeader('Content-Type', 'text/html');
pipe(res); // stream HTML to the client as it is generated
},
});
}
The key: renderToPipeableStream executes your React component functions on the server. Your component code runs in Node.js. It has access to the file system, environment variables, databases, and anything else available in a Node.js process. It does not have access to window, document, or browser APIs.
The hydration script.
Along with the HTML, Next.js sends a small JSON payload embedded in the page that contains the data used to render the page:
<script id="__NEXT_DATA__" type="application/json">
{
"props": {
"pageProps": {
"products": [
{ "id": 1, "name": "Product A", "price": 29.99 },
{ "id": 2, "name": "Product B", "price": 49.99 }
]
}
}
}
</script>
When React hydrates on the client, it reads this data to reproduce the exact same component output as the server produced. Without this data, the client React render would need to re-fetch the data, potentially producing different results during hydration (prices might have changed between server render and client hydration), causing a mismatch.
Why hydration mismatches happen.
A hydration mismatch occurs when the server-rendered HTML and the client’s first render do not match. Common causes:
// Wrong: Date.now() produces different values on server and client
function Timestamp() {
return <p>Rendered at: {Date.now()}</p>;
}
// Wrong: typeof window check that produces different output
function PlatformInfo() {
return <p>{typeof window !== 'undefined' ? 'Browser' : 'Server'}</p>;
}
// Server renders "Server", client renders "Browser": mismatch
// Wrong: random values
function RandomId() {
return <div id={`element-${Math.random()}`} />;
}
Next.js detects mismatches in development and logs warnings. In production, React attempts to recover by re-rendering the mismatched subtree on the client, which produces a flash of corrected content and a console error.
The 'use client' boundary.
In the App Router, Next.js defaults all components to Server Components. Server Components never run in the browser. They cannot use useState, useEffect, browser APIs, or event handlers. The 'use client' directive marks a component as a Client Component, meaning it will be included in the JavaScript bundle and run in the browser after hydration.
// This runs ONLY on the server. Never in the browser.
// Can access databases, file system, env variables.
// Cannot use useState, useEffect, onClick.
async function ProductList() {
const products = await db.query('SELECT * FROM products');
return (
<ul>
{products.map((p) => (
<li key={p.id}>{p.name}</li>
))}
</ul>
);
}
// This runs in the browser (and also on the server for SSR).
// Can use useState, useEffect, onClick.
// Cannot directly access databases or file system.
('use client');
function AddToCartButton({ productId }) {
const [added, setAdded] = React.useState(false);
return <button onClick={() => setAdded(true)}>{added ? 'Added' : 'Add to cart'}</button>;
}
This boundary is the core architectural concept of the App Router and is covered in full depth in Phase 2.2 + 2.3.
7. Interview Traps
Trap 1: “Next.js eliminates the need for useEffect for data fetching.” Is this accurate?
Answer
Partially accurate, but the precision matters. In the App Router with Server Components, you fetch data directly in the component using async/await without useEffect. This works because the component runs on the server where async operations are fully supported at the top level. useEffect does not exist on the server. For server components, data fetching is just await fetchData() in the function body.
However, useEffect for data fetching is still valid and sometimes necessary in Client Components. If you need to fetch data in response to user interaction, after mount (for data that does not need to be server-rendered), or when the component is a Client Component that cannot be converted to a Server Component, useEffect remains appropriate.
The accurate statement: Next.js App Router eliminates useEffect for initial page data fetching in Server Components by allowing direct async data access in the component body. For client-side data fetching driven by user interaction or Client Component constraints, useEffect or a data fetching library (React Query, SWR) remains the correct tool.
Trap 2: A developer says “hydration just means React re-renders the page in the browser after SSR.” What is wrong with this?
Answer
“Re-render” implies React discards the server-rendered HTML and creates new DOM nodes from scratch. Hydration does not do this. Hydration is React walking the existing server-rendered DOM, matching each DOM node to the corresponding component in the component tree, and attaching JavaScript behavior (event listeners, state, refs) to the existing nodes.
The existing DOM nodes are not replaced. They are adopted. This is what makes hydration fast: the browser has already parsed and laid out the HTML from the server response. Hydration does not trigger a repaint or reflow for matching nodes. It is purely a JavaScript operation that attaches behavior to existing structure.
If React did re-render (destroy and recreate DOM nodes), the user would see a flash as the DOM was torn down and rebuilt, CSS animations would reset, input focus would be lost, and scroll position would jump. Hydration is specifically designed to avoid all of this by preserving the existing DOM.
The caveat: if the server HTML does not match what the client render produces (a hydration mismatch), React does fall back to re-rendering the mismatched subtree, which can produce a visible flash. This is the failure mode hydration is designed to prevent when the server and client renders are in sync.
Trap 3: When should you NOT use Next.js and stick with a pure React CSR setup?
Answer
Three specific scenarios where CSR is the correct choice.
First, fully authenticated applications with no public pages. A dashboard, admin panel, or internal tool where every route requires login has no SEO requirement. Search engines should not and cannot index pages behind authentication. The blank screen on first load is mitigated by a loading skeleton. SSR adds server infrastructure complexity without any benefit.
Second, highly dynamic real-time applications. Applications that subscribe to WebSockets, update data several times per second, and have fundamentally different content per user benefit little from server rendering. The server-rendered HTML would be immediately stale and the hydration cost would be paid for content the user never sees.
Third, applications where you control the deployment environment completely and it does not support Node.js. Next.js requires a Node.js server (or an edge runtime) to render on the server. If your hosting is purely static (S3, GitHub Pages) and you cannot add a server, CSR is the only option. Next.js’s static export mode (output: 'export') produces static files but loses all SSR, SSG with revalidation, Server Actions, and Middleware capabilities.
The heuristic: if SEO matters or first meaningful paint on a slow connection matters to your users, use Next.js. If neither matters, the added complexity of Next.js is not justified.
Self-Test
Q1. What is the specific reason data fetching in a CSR React app cannot begin until the JavaScript bundle has been fully downloaded and executed?
Answer
Data fetching in CSR React applications lives in useEffect (or in custom hooks that use useEffect). useEffect fires after a component mounts. Components mount after React has executed and rendered the component tree. React executes after the JavaScript bundle has been downloaded and parsed by the browser. The bundle download is a prerequisite for React to exist in the browser at all.
This creates a sequential waterfall: bundle download → bundle parse → React execute → component mount → useEffect fire → fetch request → data arrives → re-render. Each step cannot begin until the previous step completes. The fetch request, which is usually the slowest meaningful step in terms of user-perceived content, is at position six in this chain. On a slow connection, the first five steps alone can take 2-3 seconds before the network request for actual content even begins.
Next.js breaks this waterfall by moving data fetching to the server, where it happens before the HTML is sent. The fetch request runs in parallel with or before the HTML transmission, not after the entire JavaScript bundle has been processed by the client.
Q2. What is hydration, and what problem would occur if React re-created all DOM nodes from scratch instead of hydrating?
Answer
Hydration is the process of React running in the browser on a page that was already rendered to HTML by the server. Instead of creating new DOM nodes, React walks the existing server-rendered DOM, matches each node to the corresponding component in the component tree, and attaches JavaScript behavior: event listeners, state initialization, and refs. The DOM structure is preserved; only the JavaScript layer is added.
If React re-created all DOM nodes from scratch (a full client-side re-render), several problems would occur. The user would see a flash as the existing DOM is destroyed and rebuilt, even if the result looks identical. CSS transitions and animations that began during the server-rendered state would reset. Any input element the user had started interacting with during the brief window before JavaScript loaded would lose its focus and any typed content. Scroll position would reset to the top. The browser would need to run a full reflow and repaint for the entire page. For content-heavy pages, this reflow could take hundreds of milliseconds, making the page feel unresponsive immediately after the JavaScript loads.
Hydration avoids all of this by treating the server-rendered HTML as the correct initial DOM state and building React’s internal representation on top of it without touching the actual DOM nodes for matching elements.
Q3. What data does Next.js embed in the page alongside the server-rendered HTML, and why is it necessary for hydration?
Answer
Next.js embeds the data used to render the page as a JSON payload in a <script id="__NEXT_DATA__"> tag (Pages Router) or as inline script tags containing serialized React flight data (App Router). This data is the server-side props, query parameters, and fetched data that were used to produce the server-rendered HTML.
It is necessary because React must produce an identical component tree during hydration as the server produced during rendering. If the client React render were to re-fetch the data independently, several problems arise: the data could have changed between the server render and the client hydration (prices, stock levels, user names), producing a mismatch between the existing server-rendered HTML and the new client render. React would detect the mismatch and re-render the mismatched subtrees, causing a visible flash of incorrect content.
By embedding the server data in the page, the client React render can use the exact same data the server used, producing the exact same component output, and hydration completes without any DOM corrections. The user sees consistent content from the moment the HTML loads through the completion of hydration.