Challenge - 5 Problems
Revalidation Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens after calling a server action that mutates data with revalidation?
Consider a Next.js server action that updates a database and triggers revalidation of a page. What will the user see immediately after the mutation completes?
NextJS
export async function updateData() { // mutation logic await revalidatePath('/dashboard'); } export default function Dashboard() { const [data, setData] = React.useState(null); React.useEffect(() => { fetch('/api/data').then(res => res.json()).then(setData); }, []); return <div>{data?.message}</div>; }
Attempts:
2 left
💡 Hint
Think about how Next.js cache and revalidation work with server actions.
✗ Incorrect
Revalidation updates server cache but does not automatically trigger client-side fetches or state updates. The client component must refetch or be remounted to update.
📝 Syntax
intermediate2:00remaining
Which code snippet correctly triggers revalidation after a mutation in Next.js?
You want to update user info and then revalidate the profile page. Which code correctly calls revalidation after mutation?
Attempts:
2 left
💡 Hint
Remember to await both mutation and revalidation calls.
✗ Incorrect
Both updateUser and revalidatePath are async and must be awaited to ensure mutation finishes before revalidation triggers.
🔧 Debug
advanced2:00remaining
Why does revalidation not update the page after mutation?
You call revalidatePath('/home') after a mutation, but the page still shows old data. What is the most likely cause?
NextJS
export async function updateItem() { await mutateDatabase(); // missing revalidation call } export default function Home() { const data = fetchData(); return <div>{data.title}</div>; }
Attempts:
2 left
💡 Hint
Check if revalidation is triggered after mutation.
✗ Incorrect
Without calling revalidatePath, Next.js does not refresh the cached data, so the page shows stale content.
🧠 Conceptual
advanced2:00remaining
What is the effect of revalidateTag compared to revalidatePath in Next.js?
You have a page that uses a cache tag 'profile'. What happens if you call revalidateTag('profile') after a mutation instead of revalidatePath('/profile')?
Attempts:
2 left
💡 Hint
Think about cache tagging and how it groups data.
✗ Incorrect
revalidateTag invalidates all cache entries with the given tag, so multiple pages or components sharing that tag get updated.
❓ state_output
expert2:00remaining
What is the state of a client component after a server action triggers revalidation?
A client component fetches data from a server component. After a server action mutates data and calls revalidatePath, what happens to the client component's state?
NextJS
export default function ClientComponent() { const [message, setMessage] = React.useState('Loading...'); React.useEffect(() => { fetch('/api/message').then(res => res.json()).then(data => setMessage(data.text)); }, []); return <p>{message}</p>; } // Server action calls revalidatePath('/client') after mutation
Attempts:
2 left
💡 Hint
Consider how client components fetch data and how revalidation affects server cache.
✗ Incorrect
Revalidation updates server cache but does not automatically trigger client-side fetches or state updates. The client component must refetch or be remounted to update.