0
0
NextJSframework~20 mins

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

Choose your learning style9 modes available
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.