JavaScript and React course Β· Module 10: React Ecosystem and Future

React 19.2 - Partial Pre-rendering (PPR)

13 min read Β·
In this lesson9

The mission page has a fixed header and menu, but the list of active missions has to be fetched on every request. Static generation (SSG) delivers the skeleton instantly, but with stale data, and SSR delivers fresh data, but the user waits for the slowest query. Partial Pre-rendering (PPR) combines both worlds on a single page, like a ship with a route calculated before launch that corrects its course when new data arrives.

What Is Partial Pre-rendering?

PPR pre-renders the static parts of a page at build time, renders the dynamic ones at request time and streams them to the client as they become ready. React 19.2 added a low-level API to react-dom: prerender returns a ready shell (prelude) and a postponed state (postponed), and resume finishes the rendering later. Next.js builds a convenient layer on top of it. This is how the page is split:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           Web Page                       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚    HEADER (pre-rendered)         β”‚    β”‚ ← Instant
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚    SIDEBAR (pre-rendered)        β”‚    β”‚ ← Instant
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚    CONTENT (Suspense boundary)   β”‚    β”‚ ← Streaming
β”‚  β”‚    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚    β”‚
β”‚  β”‚    β”‚  Loading...           β”‚     β”‚    β”‚
β”‚  β”‚    β”‚  β†’ Dynamic content    β”‚     β”‚    β”‚
β”‚  β”‚    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

The header and sidebar reach the browser immediately, and the fallback in place of the content turns into data a moment later. The boundary is marked by <Suspense>.

PPR in React Itself: prerender and resume

Next.js does not invent its own mechanism here, it uses the API added in React 19.2. At build time prerender from react-dom/static renders the app, and when you abort it with an AbortController signal, the Suspense boundaries whose data is not ready go into the shell as fallbacks, while their state lands in the postponed object. On a request, resume from react-dom/server finishes the rendering from exactly that point:

// build.js - build step
import { prerender } from 'react-dom/static';

const controller = new AbortController();
setTimeout(() => controller.abort(), 100); // After a moment, stop waiting for request data

const { prelude, postponed } = await prerender(<MissionsPage />, {
  signal: controller.signal,
});
await saveShell(prelude);            // Static HTML shell, e.g. for a CDN
await savePostponedState(postponed); // State of the postponed Suspense boundaries

// server.js - on every request
import { resume } from 'react-dom/server';

const postponedState = await loadPostponedState();
const stream = await resume(<MissionsPage />, postponedState);
// The browser first gets the shell from the CDN, then this stream with the rest of the HTML

prelude is the ready HTML of the shell, and postponed is a plain JSON object that you save and read back on a request. If everything managed to render, postponed is null. For generating static pages there is also resumeAndPrerender from react-dom/static, and in Node.js the variants for Node streams: resumeToPipeableStream and prerenderToNodeStream.

How Does PPR Work?

Configuration in Next.js

In Next.js 15 PPR was experimental and was switched on with the experimental.ppr flag. Next.js 16 removed it, and PPR is the default behavior once Cache Components are enabled:

// next.config.js (Next.js 16+)
module.exports = {
  cacheComponents: true, // Enables Cache Components, and with them Partial Pre-rendering
};

With Cache Components data is dynamic by default, and the shell gets whatever does not read request data or is marked with the 'use cache' directive. Request data means cookies(), headers(), searchParams, params without generateStaticParams, uncached fetches and a call to connection(). A component that uses them has to sit inside <Suspense>, otherwise Next.js reports a prerendering error. Cache Components requires the Node.js runtime, so routes with the deprecated runtime = 'edge' export have to be moved.

Page Structure with PPR

A page with PPR is a regular component in which you wrap the dynamic part in Suspense:

// app/missions/page.jsx
import { Suspense } from 'react';
import MissionHeader from './MissionHeader';
import MissionSidebar from './MissionSidebar';
import MissionList from './MissionList';
import MissionListSkeleton from './MissionListSkeleton';

// This page will be partially pre-rendered
export default function MissionsPage() {
  return (
    <div className="missions-layout">
      {/* These components are static - pre-rendered */}
      <MissionHeader />
      <MissionSidebar />

      {/* This component is dynamic - streaming */}
      <Suspense fallback={<MissionListSkeleton />}>
        <MissionList />
      </Suspense>
    </div>
  );
}

MissionHeader and MissionSidebar will go into the static shell, and MissionList will render on request. The way you write components does not change.

Static Components (pre-rendered)

Static components do not fetch data or read anything from the request, so the server renders them once, at build time:

// MissionHeader.jsx - static component
export default function MissionHeader() {
  return (
    <header className="mission-header">
      <h1>Mission Control Center</h1>
      <nav>
        <a href="/missions">All Missions</a>
        <a href="/missions/active">Active</a>
        <a href="/missions/completed">Completed</a>
      </nav>
    </header>
  );
}

// MissionSidebar.jsx - static component
export default function MissionSidebar() {
  return (
    <aside className="mission-sidebar">
      <h2>Filter Missions</h2>
      <ul>
        <li>Exploration missions</li>
        <li>Research missions</li>
        <li>Rescue missions</li>
      </ul>
    </aside>
  );
}

Their HTML is the same for everyone, so it can sit in a CDN.

Dynamic Components (streaming)

A dynamic component is an asynchronous Server Component that fetches fresh data on every request:

// MissionList.jsx - dynamic Server Component
async function getMissions() {
  // Without 'use cache' fetch stores nothing: the data is fetched on every request
  const res = await fetch('https://api.space-missions.com/missions');
  return res.json();
}

export default async function MissionList() {
  const missions = await getMissions();

  return (
    <div className="mission-list">
      {missions.map(mission => (
        <MissionCard key={mission.id} mission={mission} />
      ))}
    </div>
  );
}

// MissionListSkeleton.jsx - fallback during loading
export default function MissionListSkeleton() {
  return (
    <div className="mission-list skeleton">
      {[1, 2, 3].map(i => (
        <div key={i} className="mission-card-skeleton">
          <div className="skeleton-title" />
          <div className="skeleton-text" />
          <div className="skeleton-text short" />
        </div>
      ))}
    </div>
  );
}

With Cache Components a fetch without the 'use cache' directive stores nothing, so the list is fetched on every request, and until the data arrives you see MissionListSkeleton. The skeleton should have the dimensions of the list, so the content does not jump.

Benefits of PPR

Faster Time To First Byte (TTFB)

Compare the request timeline without PPR and with PPR:

Without PPR:
Request β†’ Render everything β†’ Response
         [==========] 800ms

With PPR:
Request β†’ Pre-rendered shell β†’ Response (instant)
          Dynamic parts β†’ Stream
         [==] 50ms (shell)
             [======] 750ms (dynamic, streaming)

The numbers in the diagram are illustrative. The shell goes out immediately, so the first byte does not wait for the slowest query.

Better Core Web Vitals

On the dashboard, every widget with data gets its own Suspense boundary:

// Page with multiple dynamic sections
export default function DashboardPage() {
  return (
    <div className="dashboard">
      {/* Static layout - instant LCP */}
      <DashboardHeader />
      <DashboardNav />

      <main className="dashboard-content">
        {/* Dynamic widgets - streaming */}
        <Suspense fallback={<WidgetSkeleton />}>
          <ActiveMissionsWidget />
        </Suspense>

        <Suspense fallback={<WidgetSkeleton />}>
          <CrewStatusWidget />
        </Suspense>

        <Suspense fallback={<WidgetSkeleton />}>
          <ResourcesWidget />
        </Suspense>
      </main>
    </div>
  );
}

The static header speeds up FCP and LCP, and the widgets load independently. Set a performance budget, meaning limits for metrics such as bundle size or load time, and check it on every deployment.

Hierarchical Suspense

Boundaries can be nested, so that dependent sections appear in layers:

export default function MissionDetailsPage({ params }) {
  // params is a promise: the page does not wait for it, it passes it on
  return (
    <div className="mission-details">
      {/* Level 1: Main mission data */}
      <Suspense fallback={<MissionHeaderSkeleton />}>
        <MissionHeader params={params} />

        {/* Level 2: Crew (depends on mission data) */}
        <Suspense fallback={<CrewListSkeleton />}>
          <CrewList params={params} />
        </Suspense>

        {/* Level 2: Timeline */}
        <Suspense fallback={<TimelineSkeleton />}>
          <MissionTimeline params={params} />
        </Suspense>
      </Suspense>
    </div>
  );
}

async function CrewList({ params }) {
  const { id } = await params; // We wait only inside the Suspense boundary
  const crew = await getCrew(id);

  return (
    <ul>
      {crew.map(member => (
        <li key={member.id}>{member.name}</li>
      ))}
    </ul>
  );
}

The crew and the timeline will appear after the mission header, each one separately. In Next.js 15 and 16 params is a promise, which is why the page does not wait for it itself, it passes it to the children, and only the components inside Suspense read id. Thanks to that the page layout and the fallbacks still go into the static shell.

Practical Example - Space Dashboard

The full dashboard combines a static part with two dynamic sections:

// app/dashboard/page.jsx
import { Suspense } from 'react';
import { connection } from 'next/server';

// Static layout - goes into the shell
function DashboardLayout({ children }) {
  return (
    <div className="space-dashboard">
      <header className="dashboard-header">
        <h1>Galactic Control Center</h1>
        <Suspense fallback={<time>...</time>}>
          <CurrentDate />
        </Suspense>
      </header>
      {children}
    </div>
  );
}

// The date of the request, not of the build
async function CurrentDate() {
  await connection(); // From here on, render at request time
  return <time>{new Date().toLocaleDateString('en-US')}</time>;
}

// Dynamic component - fetches real-time data
async function LiveMissionFeed() {
  // Without 'use cache' every request fetches fresh data
  const missions = await fetch('https://api.space/missions/live').then(r => r.json());

  return (
    <section className="live-feed">
      <h2>Active Missions</h2>
      {missions.map(m => (
        <article key={m.id} className="mission-item">
          <h3>{m.name}</h3>
          <p>Status: {m.status}</p>
          <p>Progress: {m.progress}%</p>
        </article>
      ))}
    </section>
  );
}

// Dynamic component - notifications
async function NotificationsPanel() {
  const notifications = await fetch('https://api.space/notifications').then(r => r.json());

  return (
    <aside className="notifications">
      <h2>Notifications</h2>
      {notifications.map(n => (
        <div key={n.id} className={`notification ${n.priority}`}>
          {n.message}
        </div>
      ))}
    </aside>
  );
}

// Static component - general statistics
function GeneralStats() {
  return (
    <div className="stats-panel">
      <h2>Fleet Statistics</h2>
      <ul>
        <li>Active ships: 47</li>
        <li>Completed missions: 1,234</li>
        <li>Crew members: 892</li>
      </ul>
    </div>
  );
}

// Main page with PPR
export default function DashboardPage() {
  return (
    <DashboardLayout>
      {/* Static - pre-rendered */}
      <GeneralStats />

      <div className="dynamic-content">
        {/* Dynamic - streaming */}
        <Suspense fallback={<div className="skeleton feed-skeleton" />}>
          <LiveMissionFeed />
        </Suspense>

        <Suspense fallback={<div className="skeleton notif-skeleton" />}>
          <NotificationsPanel />
        </Suspense>
      </div>
    </DashboardLayout>
  );
}

GeneralStats belongs to the shell, while LiveMissionFeed and NotificationsPanel stream independently. The date is handled by a separate CurrentDate component: a plain new Date() in the shell would freeze the date from build time, which is why Cache Components reports a prerendering error then. await connection() moves the rendering of this one component to request time, and Suspense shows a fallback in the meantime. You can also display the date in a client component.

Controlling Cache Behavior

With Cache Components, what goes into the shell is decided by directives and functions in the component code. You mark data shared by everyone with 'use cache' plus cacheLife and cacheTag, and you read a specific user's data inside Suspense:

// app/missions/page.jsx
import { Suspense } from 'react';
import { cookies } from 'next/headers';
import { cacheLife, cacheTag } from 'next/cache';

// Shared by everyone - goes into the static shell
async function FleetStats() {
  'use cache';
  cacheLife('hours'); // Refresh every hour
  cacheTag('fleet'); // revalidateTag('fleet', 'max') refreshes the data on demand

  const stats = await fetch('https://api.space/fleet/stats').then(r => r.json());
  return <p>Active ships: {stats.activeShips}</p>;
}

// Depends on a cookie - rendered on every request
async function PilotGreeting() {
  const pilot = (await cookies()).get('pilot')?.value ?? 'astronaut';
  return <p>Welcome, {pilot}!</p>;
}

export default function MissionsPage() {
  return (
    <main>
      <h1>Mission Control Center</h1>
      <FleetStats />
      <Suspense fallback={<p>Connecting to the pilot...</p>}>
        <PilotGreeting />
      </Suspense>
    </main>
  );
}

The heading and FleetStats go into the shell because they do not depend on the request, while every user gets their own greeting. Without Cache Components, rendering was decided by route segment config exports such as dynamic = 'force-static', dynamic = 'force-dynamic' or revalidate. Once cacheComponents is enabled, these exports cause an error: instead of force-static you mark the data with the 'use cache' directive, instead of revalidate you set cacheLife, and force-dynamic is unnecessary, because without 'use cache' everything is dynamic.

When to Use PPR?

ScenarioRecommendation
Landing page with a dynamic heroPPR
Dashboard with real-time dataPPR
E-commerce with prices/availabilityPPR
Blog with static contentFull SSG
SPA application without SEOClient-side
Page with personalizationPPR

Comparing Rendering Strategies

Choosing a strategy is part of architecture planning: first you analyze the requirements, such as data freshness, SEO and personalization, and then you pick the rendering:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Strategy       β”‚ Characteristics                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ SSG            β”‚ Entirely pre-rendered, no dynamics       β”‚
β”‚ SSR            β”‚ Entirely rendered per request            β”‚
β”‚ ISR            β”‚ Pre-rendered with revalidation           β”‚
β”‚ CSR            β”‚ Entirely rendered on the client          β”‚
β”‚ PPR            β”‚ Static shell + dynamic streaming         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

SSG:   [β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ] β†’ Client (instant, but stale)
SSR:   [............] β†’ [β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ] β†’ Client (slower)
PPR:   [β–ˆβ–ˆβ–ˆβ–ˆ] β†’ [β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘] β†’ Client (fast shell + streaming)

PPR combines SSG and SSR on a single page without replacing them. In the browser every strategy ends in a similar way: first the HTML becomes visible (FCP), then the JavaScript arrives, and React hydrates the page by attaching event handlers, so onClick works only after hydration. Identifiers must match on the server and in the browser, so generate them with useId, not Math.random(). Streaming builds on concurrent React from the previous location: createRoot, automatic batching of updates, startTransition and useDeferredValue.

Debugging PPR

The most reliable test of the split is a production build. next build prints a route table, and the symbol next to each route tells you how it will be served:

Route (app)
β”Œ β—‹ /
β”œ β—‹ /about
β”” ◐ /missions

β—‹  (Static)             prerendered as static content
◐  (Partial Prerender)  prerendered as static HTML with dynamic server-streamed content

β—‹ means a fully static page, and ◐ a page with a static shell and dynamic parts streamed in. If a component reads request data or fetches uncached data outside <Suspense>, the build stops with an error and suggests three ways out: add a Suspense boundary, cache the data with 'use cache', or knowingly let the route block rendering. next build --debug-prerender gives you a precise stack trace, and in development the Next.js overlay shows the same problems. You can inspect the component tree, props and state in React DevTools, and since React 19.2 Chrome DevTools also show React performance tracks (Scheduler and Components).

Summary

  1. The best of both worlds - the speed of static + the freshness of dynamic
  2. Automatic splitting - Next.js determines the shell based on Suspense boundaries and data
  3. HTML streaming - the user sees content progressively
  4. Suspense boundaries - you control the granularity of the dynamic parts
  5. Better Core Web Vitals - especially LCP and FCP

My advice: start with a static shell and push the Suspense boundaries as low as possible, down to the smallest component that really needs request data.

Remember: PPR is the ship's hybrid drive - the static shell launches instantly, and the dynamic modules join in flight. In the example below click "New request": the shell with the menu and filters stays in place, while the sections inside Suspense boundaries, including the now finished resources widget, stream in again with data from the next request.

Code for this lesson: App.jsx
import { Suspense, use, useState } from 'react';

// === PARTIAL PRE-RENDERING (PPR) - a simulation in the browser ===
// The static shell (header, menu, filters) is ready immediately, like HTML built
// during "next build". Sections inside Suspense boundaries stream in on every
// request. The "New request" button shows that the shell stays while the data is fresh.

const BUILD_TIME = new Date().toLocaleTimeString('en-US'); // The moment the shell was "built"

const requests = new Map();

// Dynamic data: one promise per section in a given request
function fetchForRequest(section, requestId, delay, makeData) {
  const key = section + ':' + requestId;
  if (!requests.has(key)) {
    requests.set(key, new Promise(resolve => setTimeout(() => {
      resolve({ data: makeData(requestId), time: new Date().toLocaleTimeString('en-US') });
    }, delay)));
  }
  return requests.get(key);
}

const vary = (base, requestId, spread) => Math.min(100, base + ((requestId * 7) % spread));

// === STATIC SHELL (prerendered) ===

function MissionHeader() {
  return (
    <header style={styles.header}>
      <h1 style={styles.headerTitle}>Mission Control Center</h1>
      <nav style={styles.nav}>
        <a href="#all" style={styles.navLink}>All missions</a>
        <a href="#active" style={{ ...styles.navLink, ...styles.navLinkActive }}>Active</a>
        <a href="#completed" style={styles.navLink}>Completed</a>
      </nav>
    </header>
  );
}

function MissionSidebar() {
  const filters = ['Exploration', 'Research', 'Rescue', 'Transport'];

  return (
    <aside style={styles.sidebar}>
      <h3 style={{ color: '#00d4ff', marginTop: 0, fontSize: '16px' }}>Filter missions</h3>
      {filters.map(filter => (
        <label key={filter} style={styles.filterLabel}>
          <input type="checkbox" style={{ accentColor: '#00d4ff' }} />
          <span>{filter}</span>
        </label>
      ))}
      <div style={styles.staticBadge}>STATIC SHELL</div>
      <p style={styles.meta}>Built at {BUILD_TIME}</p>
    </aside>
  );
}

// === DYNAMIC SECTIONS (streaming inside Suspense boundaries) ===

function StreamedBadge({ requestId, time }) {
  return (
    <span style={styles.dynamicBadge}>STREAMING - request #{requestId}, {time}</span>
  );
}

function ActiveMissionsWidget({ requestId }) {
  const { data, time } = use(fetchForRequest('missions', requestId, 1500, id => [
    { id: 1, name: 'Orion Nebula Exploration', progress: vary(70, id, 25) },
    { id: 2, name: 'Dark Matter Probe', progress: vary(40, id, 30) },
    { id: 3, name: 'Asteroid Belt Patrol', progress: vary(85, id, 15) },
  ]));

  return (
    <section style={styles.panel}>
      <div style={styles.panelHeader}>
        <h3 style={styles.panelTitle}>Active missions</h3>
        <StreamedBadge requestId={requestId} time={time} />
      </div>
      <div style={styles.missionGrid}>
        {data.map(m => (
          <div key={m.id} style={styles.card}>
            <h4 style={{ margin: '0 0 8px', fontSize: '14px' }}>{m.name}</h4>
            <div style={styles.progressBar}>
              <div style={{ ...styles.progressFill, width: m.progress + '%' }} />
            </div>
            <span style={{ color: '#00ff88', fontSize: '12px' }}>{m.progress}%</span>
          </div>
        ))}
      </div>
    </section>
  );
}

function CrewStatusWidget({ requestId }) {
  const { data, time } = use(fetchForRequest('crew', requestId, 2200, id => [
    { name: 'Commander Nova', location: 'Bridge', active: true },
    { name: 'Astro', location: 'Navigation', active: true },
    { name: 'Ra', location: 'Laboratory', active: id % 2 === 0 },
  ]));

  return (
    <section style={styles.panel}>
      <div style={styles.panelHeader}>
        <h3 style={styles.panelTitle}>Crew status</h3>
        <StreamedBadge requestId={requestId} time={time} />
      </div>
      {data.map(c => (
        <div key={c.name} style={styles.row}>
          <span>{c.name}</span>
          <span style={styles.meta}>{c.location}</span>
          <span style={{ ...styles.dot, background: c.active ? '#00ff88' : '#ffa500' }} />
        </div>
      ))}
    </section>
  );
}

function ResourcesWidget({ requestId }) {
  const { data, time } = use(fetchForRequest('resources', requestId, 3000, id => [
    { name: 'Fuel', level: vary(60, id, 30) },
    { name: 'Oxygen', level: vary(85, id, 15) },
    { name: 'Energy', level: vary(70, id, 25) },
    { name: 'Water', level: vary(50, id, 35) },
    { name: 'Food', level: vary(40, id, 40) },
  ]));

  return (
    <section style={styles.panel}>
      <div style={styles.panelHeader}>
        <h3 style={styles.panelTitle}>Ship resources</h3>
        <StreamedBadge requestId={requestId} time={time} />
      </div>
      {data.map(r => (
        <div key={r.name} style={styles.resource}>
          <span style={{ width: '70px' }}>{r.name}</span>
          <div style={styles.progressBar}>
            <div style={{ ...styles.progressFill, width: r.level + '%', background: r.level < 50 ? '#ffa500' : '#00ff88' }} />
          </div>
          <span style={{ width: '40px', textAlign: 'right' }}>{r.level}%</span>
        </div>
      ))}
    </section>
  );
}

function TelemetryReport({ requestId }) {
  const { time } = use(fetchForRequest('telemetry', requestId, 3500, () => null));

  return (
    <section style={{ ...styles.panel, textAlign: 'center' }}>
      <StreamedBadge requestId={requestId} time={time} />
      <p style={{ color: '#64ffda', margin: '8px 0 0' }}>Telemetry analysis complete - all systems operational.</p>
    </section>
  );
}

function SkeletonCard({ lines = 3 }) {
  return (
    <div style={styles.panel}>
      <div style={{ ...styles.skeletonLine, width: '50%', height: '16px' }} />
      {Array.from({ length: lines }).map((_, i) => (
        <div key={i} style={{ ...styles.skeletonLine, width: 85 - i * 12 + '%' }} />
      ))}
    </div>
  );
}

export default function App() {
  const [requestId, setRequestId] = useState(1);

  return (
    <div style={styles.container}>
      <MissionHeader />

      <div style={styles.layout}>
        <MissionSidebar />

        <main key={requestId} style={styles.main}>
          <div style={styles.toolbar}>
            <button style={styles.button} onClick={() => setRequestId(id => id + 1)}>New request</button>
            <span style={styles.meta}>The shell stays in place, the data streams in again (request #{requestId})</span>
          </div>

          <Suspense fallback={<SkeletonCard lines={3} />}>
            <ActiveMissionsWidget requestId={requestId} />
          </Suspense>

          <div style={styles.twoColumns}>
            <Suspense fallback={<SkeletonCard lines={3} />}>
              <CrewStatusWidget requestId={requestId} />
            </Suspense>
            <Suspense fallback={<SkeletonCard lines={5} />}>
              <ResourcesWidget requestId={requestId} />
            </Suspense>
          </div>

          <Suspense fallback={<SkeletonCard lines={1} />}>
            <TelemetryReport requestId={requestId} />
          </Suspense>
        </main>
      </div>
      <style>{'@keyframes skeletonPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }'}</style>
    </div>
  );
}

const styles = {
  container: { minHeight: '100vh', background: 'linear-gradient(135deg, #0d1b2a 0%, #1a1a3e 100%)', color: '#e0e1dd', fontFamily: 'system-ui, sans-serif', fontSize: '13px' },
  header: { padding: '16px 24px', borderBottom: '1px solid rgba(0,212,255,0.15)', background: 'rgba(0,0,0,0.2)' },
  headerTitle: { color: '#00d4ff', margin: '0 0 10px', fontSize: '22px' },
  nav: { display: 'flex', gap: '16px' },
  navLink: { color: '#8892b0', textDecoration: 'none', fontSize: '14px', paddingBottom: '4px', borderBottom: '2px solid transparent' },
  navLinkActive: { color: '#00d4ff', borderBottom: '2px solid #00d4ff' },
  layout: { display: 'grid', gridTemplateColumns: '200px minmax(0, 1fr)' },
  sidebar: { padding: '16px', borderRight: '1px solid rgba(0,212,255,0.1)', background: 'rgba(0,0,0,0.15)' },
  filterLabel: { display: 'flex', alignItems: 'center', gap: '8px', padding: '6px 0', cursor: 'pointer' },
  staticBadge: { display: 'inline-block', marginTop: '14px', padding: '3px 8px', background: 'rgba(0,212,255,0.15)', border: '1px solid rgba(0,212,255,0.3)', borderRadius: '4px', color: '#00d4ff', fontSize: '10px', fontWeight: 'bold' },
  main: { padding: '16px', display: 'grid', gap: '12px', alignContent: 'start' },
  toolbar: { display: 'flex', alignItems: 'center', gap: '10px', flexWrap: 'wrap' },
  button: { padding: '6px 14px', background: '#00d4ff', color: '#0d1b2a', border: 'none', borderRadius: '6px', fontWeight: 'bold', cursor: 'pointer' },
  meta: { color: '#8892b0', fontSize: '12px' },
  panel: { background: 'rgba(0,0,0,0.3)', borderRadius: '12px', padding: '14px', border: '1px solid rgba(0,212,255,0.15)' },
  panelHeader: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: '8px', marginBottom: '10px', flexWrap: 'wrap' },
  panelTitle: { color: '#00d4ff', margin: 0, fontSize: '15px' },
  dynamicBadge: { display: 'inline-block', padding: '3px 8px', background: 'rgba(0,255,136,0.12)', border: '1px solid rgba(0,255,136,0.3)', borderRadius: '4px', color: '#00ff88', fontSize: '10px', fontWeight: 'bold' },
  missionGrid: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(150px, 1fr))', gap: '10px' },
  card: { padding: '12px', background: 'rgba(0,0,0,0.3)', borderRadius: '10px', border: '1px solid rgba(0,212,255,0.1)' },
  progressBar: { flex: 1, height: '6px', background: 'rgba(255,255,255,0.1)', borderRadius: '3px', margin: '6px 0', overflow: 'hidden' },
  progressFill: { height: '100%', background: 'linear-gradient(90deg, #00d4ff, #00ff88)' },
  twoColumns: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(220px, 1fr))', gap: '12px' },
  row: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: '8px', padding: '8px', background: 'rgba(0,0,0,0.2)', borderRadius: '6px', marginBottom: '4px' },
  dot: { width: '8px', height: '8px', borderRadius: '50%' },
  resource: { display: 'flex', alignItems: 'center', gap: '8px', marginBottom: '6px' },
  skeletonLine: { height: '12px', background: 'rgba(0,212,255,0.1)', borderRadius: '4px', marginBottom: '8px', animation: 'skeletonPulse 1.5s infinite' },
};

Docs entries used in this lesson

Spotted a mistake in this lesson?

Check yourself

Answer the questions from this lesson. Pick an answer to see right away whether it is correct.

  1. 1. What is Partial Pre-rendering (PPR)?

  2. 2. Which tool from the React ecosystem is used to inspect the component tree and their props/state in the browser?

These are 2 of 4 questions for this lesson. Solve the rest in the game.

Hands-on tasks in the game

  • Vertical ordering

    Order the steps of the Server-Side Rendering and hydration process:

  • Vertical ordering

    Order the steps of adopting concurrent features (Concurrent React) in an existing app:

  • Click in order

    Arrange the declaration and usage of the useId hook to connect a label with an input:

  • Code editor

    Finish the mission control reducer. The launch action launches a planned mission if there is enough fuel. ___BLANK1___: the new fuel value is the fuel from state minus the fuelCost of the launched mission. ___BLANK2___: the launched mission becomes a new object with all the fields of the old one and the status 'in flight' (spread, without changing the old object). ___BLANK3___: App creates the state and dispatch with useReducer from missionReducer and initialState. The reducer must not mutate state: it always returns new objects and arrays.

  • Click in order

    Arrange the code for using startTransition to mark an update as non-urgent:

  • Code editor

    Make the navigation map respond smoothly despite a catalogue of 3000 stars. ___BLANK1___: deferredQuery is the deferred version of query from useDeferredValue - the text field shows the typed text at once, while the list filters in the background (until then it is dimmed, because isStale is true). ___BLANK2___: take isPending and startTransition from the useTransition hook. ___BLANK3___: selectTab changes the tab with startTransition(() => setTab(next)), so a message with role="status" shows up while switching.

  • Vertical ordering

    Order event handling in React:

  • Code editor

    Finish the Core Web Vitals panel of the observatory. Thresholds (web.dev): LCP is good up to 2500 ms and needs improvement up to 4000 ms; INP is good up to 200 ms and needs improvement up to 500 ms; CLS is good up to 0.1 and needs improvement up to 0.25; above that it is poor. ___BLANK1___: rateMetric returns needs-improvement when the value does not exceed the poor threshold of that metric (the threshold itself counts). ___BLANK2___: the card border colour is the colour of the rating from the COLORS object. ___BLANK3___: summarize increases by 1 the counter of the category the metric falls into. For the probe measurements the summary is: 1 good, 1 needs improvement, 1 poor.

  • Click in order

    Arrange a component that defers filtering the star list with useDeferredValue and dims the stale result:

  • Code editor

    Build the missions page in the App Router architecture: MissionsPage is an async Server Component, and MissionFilter is a Client Component with state. ___BLANK1___: MissionsPage waits for the data from getMissions() (await). ___BLANK2___: pass the mission list to MissionFilter through the missions prop. ___BLANK3___: when Active only is checked, the filter keeps the missions with the status 'active'. The Server Component has no state and no event handling - all of that lives in the client component. The editor preview pretends to be Next.js, so the page shows up after about half a second.

  1. QuestionPartial Pre-rendering (PPR)
  2. Put in orderSSR and Hydration Process
  3. Put in orderConcurrent React Implementation
  4. Click in orderuseId Syntax for Accessibility
  5. Coding taskPractice: Complex State with useReducer
  6. Click in orderuseTransition Usage Pattern
  7. Coding taskPractice: Concurrent Rendering
  8. Put in orderEvent Handling in React
  9. Coding taskPractice: Performance Observatory
  10. Click in orderuseDeferredValue Pattern
  11. Coding taskPractice: Server and Client Components
  12. QuestionReact DevTools
  13. QuestionProduction Architecture Planning
  14. QuestionPerformance Budgeting

Useful articles