Bird
Raised Fist0
NextJSframework~20 mins

Streaming and partial rendering in NextJS - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Streaming Mastery in Next.js
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What will this Next.js streaming component render first?

Consider this Next.js server component using streaming:

export default async function Page() {
  const data = await fetch('https://api.example.com/data').then(res => res.json())
  return (
    <main>
      <h1>Welcome</h1>
      <section>{data.message}</section>
    </main>
  )
}

What part of the page will the browser display first during streaming?

NextJS
export default async function Page() {
  const data = await fetch('https://api.example.com/data').then(res => res.json())
  return (
    <main>
      <h1>Welcome</h1>
      <section>{data.message}</section>
    </main>
  )
}
AThe &lt;h1&gt;Welcome&lt;/h1&gt; renders immediately, then &lt;section&gt; with data appears after fetch.
BThe entire page renders only after data is fully fetched.
COnly the &lt;section&gt; renders first, &lt;h1&gt; appears after data fetch.
DNothing renders until the fetch completes.
Attempts:
2 left
💡 Hint

Without Suspense boundaries, top-level awaits in server components block rendering of the entire page.

📝 Syntax
intermediate
2:00remaining
Which Next.js code snippet correctly enables streaming with Suspense?

Choose the correct way to use React Suspense for streaming in a Next.js server component:

NextJS
import React, { Suspense } from 'react';

function Loading() {
  return <p>Loading...</p>;
}

async function DataComponent() {
  const data = await fetch('https://api.example.com/data').then(res => res.json());
  return <p>{data.message}</p>;
}

export default function Page() {
  return (
    <main>
      <h1>Title</h1>
      {/* Suspense usage here */}
    </main>
  );
}
A
&lt;Suspense fallback={&lt;Loading /&gt;}&gt;
  {DataComponent()}
&lt;/Suspense&gt;
B
&lt;Suspense fallback={&lt;Loading /&gt;}&gt;
  {await &lt;DataComponent /&gt;}
&lt;/Suspense&gt;
C
&lt;Suspense fallback={&lt;Loading /&gt;}&gt;
  &lt;DataComponent /&gt;
&lt;/Suspense&gt; // but DataComponent is async function
D
&lt;Suspense fallback={&lt;Loading /&gt;}&gt;
  &lt;DataComponent /&gt;
&lt;/Suspense&gt;
Attempts:
2 left
💡 Hint

Remember Suspense expects components, not promises or awaited JSX.

🔧 Debug
advanced
2:00remaining
Why does this Next.js streaming page block rendering until all data loads?

Given this Next.js server component using streaming, why does the browser wait for all data before showing anything?

export default async function Page() {
  const user = await fetch('/api/user').then(r => r.json())
  const posts = await fetch('/api/posts').then(r => r.json())
  return (
    <main>
      <h1>Hello {user.name}</h1>
      <ul>
        {posts.map(post => <li key={post.id}>{post.title}</li>)}
      </ul>
    </main>
  )
}
NextJS
export default async function Page() {
  const user = await fetch('/api/user').then(r => r.json())
  const posts = await fetch('/api/posts').then(r => r.json())
  return (
    <main>
      <h1>Hello {user.name}</h1>
      <ul>
        {posts.map(post => <li key={post.id}>{post.title}</li>)}
      </ul>
    </main>
  )
}
ABecause both fetch calls are awaited sequentially before returning JSX, blocking streaming.
BBecause Next.js disables streaming when multiple fetches are used.
CBecause the component uses client-side rendering instead of server streaming.
DBecause the JSX syntax is invalid and prevents streaming.
Attempts:
2 left
💡 Hint

Think about when the component returns JSX in relation to async calls.

state_output
advanced
2:00remaining
What is the rendered output of this Next.js streaming component with nested Suspense?

Analyze this Next.js component using nested Suspense for streaming partials:

import React, { Suspense } from 'react';

function LoadingUser() { return <p>Loading user...</p> }
function LoadingPosts() { return <p>Loading posts...</p> }

async function User() {
  const user = await fetch('/api/user').then(r => r.json())
  return <h2>User: {user.name}</h2>
}

async function Posts() {
  const posts = await fetch('/api/posts').then(r => r.json())
  return <ul>{posts.map(p => <li key={p.id}>{p.title}</li>)}</ul>
}

export default function Page() {
  return (
    <main>
      <h1>Dashboard</h1>
      <Suspense fallback=<LoadingUser />>
        <User />
      </Suspense>
      <Suspense fallback=<LoadingPosts />>
        <Posts />
      </Suspense>
    </main>
  )
}

What will the user see first in the browser?

NextJS
import React, { Suspense } from 'react';

function LoadingUser() { return <p>Loading user...</p> }
function LoadingPosts() { return <p>Loading posts...</p> }

async function User() {
  const user = await fetch('/api/user').then(r => r.json())
  return <h2>User: {user.name}</h2>
}

async function Posts() {
  const posts = await fetch('/api/posts').then(r => r.json())
  return <ul>{posts.map(p => <li key={p.id}>{p.title}</li>)}</ul>
}

export default function Page() {
  return (
    <main>
      <h1>Dashboard</h1>
      <Suspense fallback={<LoadingUser />}>
        <User />
      </Suspense>
      <Suspense fallback={<LoadingPosts />}>
        <Posts />
      </Suspense>
    </main>
  )
}
ADashboard heading, then Loading user..., then Loading posts..., then user and posts data appear.
BDashboard heading, then user data, then posts data, no loading messages.
COnly Loading user... and Loading posts... appear, no Dashboard heading.
DNothing appears until both user and posts data load.
Attempts:
2 left
💡 Hint

Suspense fallback shows while async components load.

🧠 Conceptual
expert
2:00remaining
Why is streaming with React Server Components beneficial for large Next.js apps?

Choose the best explanation for why streaming and partial rendering with React Server Components improves performance in large Next.js applications.

AIt disables client-side JavaScript, making pages static and faster to load.
BIt forces the entire page to load before rendering, ensuring consistent layout and avoiding flicker.
CIt allows sending HTML chunks as soon as parts are ready, reducing time to first meaningful paint and improving user experience.
DIt caches all data on the client to avoid any server requests after the first load.
Attempts:
2 left
💡 Hint

Think about how streaming affects perceived loading speed and interactivity.

Practice

(1/5)
1. What is the main benefit of streaming in Next.js when rendering pages?
easy
A. It caches the whole page on the client side before showing anything.
B. It delays sending the entire page until all data is loaded.
C. It disables server-side rendering completely.
D. It sends parts of the page to the browser as soon as they are ready.

Solution

  1. Step 1: Understand streaming concept in Next.js

    Streaming means sending parts of the page to the browser immediately when they are ready, not waiting for the whole page.
  2. Step 2: Compare options with streaming behavior

    It sends parts of the page to the browser as soon as they are ready. matches this behavior exactly, while others describe delaying or caching, which are not streaming.
  3. Final Answer:

    It sends parts of the page to the browser as soon as they are ready. -> Option D
  4. Quick Check:

    Streaming = send parts early [OK]
Hint: Streaming means show parts early, not wait for all [OK]
Common Mistakes:
  • Thinking streaming waits for full page
  • Confusing streaming with client caching
  • Assuming streaming disables server rendering
2. Which of the following is the correct way to use Suspense for partial rendering in Next.js?
easy
A. } />
B. } />
C. }>
D. }>

Solution

  1. Step 1: Recall Suspense usage pattern

    Suspense wraps the async component and uses the fallback prop to show a loading state while waiting.
  2. Step 2: Match correct syntax

    <Suspense fallback=<Loading />><AsyncComponent /></Suspense> correctly wraps AsyncComponent inside Suspense with fallback. Others misuse fallback or component placement.
  3. Final Answer:

    <Suspense fallback=<Loading />><AsyncComponent /></Suspense> -> Option C
  4. Quick Check:

    Suspense wraps async with fallback [OK]
Hint: Suspense wraps async component with fallback prop [OK]
Common Mistakes:
  • Placing fallback inside async component
  • Not wrapping async component with Suspense
  • Using fallback incorrectly as a child
3. Given this Next.js server component code using streaming:
export default async function Page() {
  const user = await fetchUser();
  return (
    <>
      

Welcome {user.name}

Loading posts...

}> </> ); }

What will the user see first in the browser?
medium
A. Only 'Loading posts...' until all data loads.
B. The heading with user name, then 'Loading posts...' while posts load.
C. The full page with heading and posts at once.
D. An empty page until fetchUser finishes.

Solution

  1. Step 1: Analyze async data fetching and rendering

    The user data is awaited before rendering, so the heading with user name shows immediately.
  2. Step 2: Understand Suspense fallback behavior

    The Posts component is wrapped in Suspense with a fallback, so 'Loading posts...' shows while posts load.
  3. Final Answer:

    The heading with user name, then 'Loading posts...' while posts load. -> Option B
  4. Quick Check:

    Await user shows heading first, Suspense fallback next [OK]
Hint: Awaited data shows first; Suspense fallback shows during async child load [OK]
Common Mistakes:
  • Thinking Suspense fallback shows before awaited user data
  • Assuming full page waits for all data
  • Ignoring Suspense fallback usage
4. Identify the error in this Next.js streaming code snippet:
export default async function Page() {
  return (
    Loading...

}> ); } function AsyncData() { const data = fetchData(); return <p>{data.message}</p>; }
medium
A. AsyncData is not marked async and fetchData is not awaited.
B. Suspense cannot wrap components in Next.js.
C. fetchData should be called inside Page, not AsyncData.
D. The fallback prop must be a string, not JSX.

Solution

  1. Step 1: Check AsyncData function for async usage

    AsyncData calls fetchData() but does not await it or mark function async, causing a promise to be rendered.
  2. Step 2: Confirm Suspense usage and fallback validity

    Suspense usage is correct, and fallback can be JSX, so no error there.
  3. Final Answer:

    AsyncData is not marked async and fetchData is not awaited. -> Option A
  4. Quick Check:

    Async function must await async calls [OK]
Hint: Async components must await async calls inside [OK]
Common Mistakes:
  • Not marking component async when using await
  • Rendering unresolved promises
  • Misunderstanding Suspense fallback types
5. You want to stream a page showing user info and their posts. User info loads fast, posts load slowly. How do you combine streaming and partial rendering to show user info immediately and posts with a loading fallback?
hard
A. Make Page async, await user data, render user info immediately, wrap Posts in Suspense with fallback.
B. Render user info and posts inside one Suspense with fallback for both.
C. Fetch posts first, then user info, and render all at once without Suspense.
D. Use client-side fetching for posts and server-side for user info without Suspense.

Solution

  1. Step 1: Await fast user data in Page component

    Mark Page async and await user data so user info renders immediately.
  2. Step 2: Wrap slow posts component in Suspense with fallback

    Wrap Posts in Suspense with a loading fallback to show partial rendering while posts load.
  3. Final Answer:

    Make Page async, await user data, render user info immediately, wrap Posts in Suspense with fallback. -> Option A
  4. Quick Check:

    Await fast data, Suspense slow data [OK]
Hint: Await fast data, Suspense slow parts with fallback [OK]
Common Mistakes:
  • Wrapping all content in one Suspense losing immediate render
  • Not awaiting fast data before rendering
  • Using client fetching without Suspense for server components