0
0
NextJSframework~20 mins

Cache debugging tools in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cache Debugging Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
Understanding cache behavior in Next.js Server Components
Consider a Next.js Server Component that fetches data with caching enabled. What will be the output if the cache is stale but the component is rendered again?
NextJS
export default async function Page() {
  const data = await fetch('https://api.example.com/data', { cache: 'force-cache' }).then(res => res.json());
  return <pre>{JSON.stringify(data)}</pre>;
}
AThe component shows the cached data without fetching new data.
BThe component fetches fresh data ignoring the cache and updates the output.
CThe component throws a runtime error due to stale cache.
DThe component shows empty data because the cache is stale.
Attempts:
2 left
💡 Hint
Remember that 'force-cache' uses cached data if available, even if stale.
🔧 Debug
intermediate
2:00remaining
Identifying cache invalidation issues in Next.js
You notice your Next.js app does not update data after deployment despite changes on the API. Which cache debugging tool helps you verify if the cache is causing this?
AUsing the React DevTools Profiler to check component renders.
BUsing the Next.js <code>revalidatePath</code> server action to force cache refresh.
CUsing the Next.js built-in <code>next dev</code> server with cache disabled.
DUsing the browser's Network tab to check if requests return 304 Not Modified.
Attempts:
2 left
💡 Hint
Look for HTTP status codes indicating cache hits or misses.
📝 Syntax
advanced
2:00remaining
Correct usage of cache control in Next.js fetch
Which option correctly sets the fetch cache to revalidate every 10 seconds in a Next.js Server Component?
Afetch(url, { cache: 'force-cache', next: { revalidate: 10 } })
Bfetch(url, { next: { revalidate: 10 } })
Cfetch(url, { cache: 'no-store', next: { revalidate: 10 } })
Dfetch(url, { cache: 'no-cache', next: { revalidate: 10 } })
Attempts:
2 left
💡 Hint
The 'next' option controls revalidation timing.
state_output
advanced
2:00remaining
Effect of cache on component state updates
In a Next.js app, a client component fetches data from an API and caches it. If the API data changes but the cache is not invalidated, what will the component display after a user interaction that triggers a re-render?
NextJS
'use client';
import { useState, useEffect } from 'react';

export default function ClientComponent() {
  const [data, setData] = useState(null);

  useEffect(() => {
    fetch('/api/data', { cache: 'force-cache' })
      .then(res => res.json())
      .then(setData);
  }, []);

  return <div>{data ? data.value : 'Loading...'}</div>;
}
AThe component shows the old cached data despite re-render.
BThe component shows the updated API data after re-render.
CThe component shows 'Loading...' indefinitely.
DThe component crashes with a fetch error.
Attempts:
2 left
💡 Hint
Consider how 'force-cache' affects fetch results on re-render.
🧠 Conceptual
expert
3:00remaining
Diagnosing cache-related stale data in Next.js with ISR
You deployed a Next.js app using Incremental Static Regeneration (ISR) with revalidate: 60. After updating content in the CMS, users still see old data for several minutes. Which is the most accurate explanation?
AThe browser cache is ignoring cache headers and serving old pages.
BThe Next.js cache is broken and requires manual clearing after CMS updates.
CISR revalidates pages only after the first request post revalidate time, so stale data can persist until then.
DISR immediately updates all pages on CMS content change, so this is a deployment bug.
Attempts:
2 left
💡 Hint
Think about how ISR timing works with user requests.