Next.js Interview Questions and Answers
App Router, Server and Client Components, rendering, caching, Server Actions, Next.js 16.
225 questions for Next.js interviews with answers and explanations - Junior, Middle and Senior levels. Sample questions, online quizzes and coding tasks.
- App Router
- RSC
- Caching
- Server Actions
Questions by level
Junior
Core concepts and syntax · 50 questions
Middle
Practice, nuances and optimization · 50 questions
Senior
Architecture, internals, edge cases · 50 questions
Sample questions
A few questions from each level with the correct answer and an explanation.
Next.js · Junior
- What is colocation in the App Router?
Correct answer: Keeping components and utilities next to routes inside
app/Files in
app/become public only throughpageorroute. So it's safe to keep a route's components, hooks, styles and tests next to itspage.tsx. For clarity, use private_componentsfolders or keep shared code insrc/outsideapp. - What is Next.js?
Correct answer: A React framework with routing, server rendering and optimizations
Next.js is built on React and adds what the library lacks: file-based routing, server and static rendering, Server Components and Server Functions, image and font optimization, building and deployment. Components are written in plain React.
- How do you create a page at
/aboutin the App Router?Correct answer: Create
app/about/page.tsxwith a default-exported componentA route is defined by a folder, and a
page.tsx(or.js) file makes it a public page. Withoutpage, the folder isn't reachable by URL - you can keep components in it (colocation). There's no route configuration innext.config. Apages/about.tsxfile is the old Pages Router convention. - How does
layout.tsxdiffer frompage.tsx?Correct answer: A layout wraps pages and preserves state during navigation
A layout receives
childrenand holds UI shared by nested routes (header, sidebar). When navigating between child pages, the layout doesn't remount: its state and DOM are preserved, and only the changed part renders. Both layout and page are Server Components by default.
Next.js · Middle
- What is a Server Function (Server Action) in Next.js?
Correct answer: An async function marked
'use server'that can be called from the clientThe
'use server'directive turns a function into a server function, and Next.js creates an endpoint for it. You can pass it to<form action>or call it from a client handler. The call is a POST request. Server Actions are Server Functions used for mutations, often followed by cache revalidation. - What does
<form action={createPost}>with a Server Action give you compared toonSubmit+fetch?Correct answer: The form works even before JS loads (progressive enhancement), with no API route
A Server Action receives
FormDatadirectly, so you don't need a Route Handler and a clientfetch. If the form is rendered by a server component, it submits even before hydration. You still write validation yourself (e.g. with Zod). Submission state is shown viauseActionStateoruseFormStatus. - What does
revalidatePath('/blog')do after a mutation?Correct answer: Marks the cached data and UI of the
/blogroute as staleThe next request to
/bloggets fresh data. When called in a Server Action, the updated UI comes back right in the action's response. For targeted invalidation of data used on many pages, tags are more convenient (cacheTag+revalidateTag/updateTag). - How does
updateTagdiffer fromrevalidateTagin Next.js 16?Correct answer:
updateTagexpires the cache immediately (read-your-writes),revalidateTagis stale-while-revalidateupdateTagis available only in Server Actions: the user who changed the data sees the changes immediately.revalidateTag(tag, 'max')marks data as stale: visitors see the old version while the new one is prepared in the background - good for blogs and catalogs. In Next.js 16,revalidateTagrequires a second argument - acacheLifeprofile.
Next.js · Senior
- What is the RSC payload?
Correct answer: The serialized render result of Server Components with references to client ones
The payload contains the rendered tree of server components, placeholders for client components with references to their JS chunks, and their props. On the first load it's embedded in the HTML (for hydration); during client navigation it's fetched separately. Server component code never reaches the browser.
- What happens during client navigation via
<Link>in the App Router?Correct answer: The new segment's RSC payload is loaded, and React updates only the changed parts
The router requests the payload (or takes a prefetched one from the client cache) and reconciles it with the current tree: shared layouts are preserved and client state isn't lost. If the segment is still loading,
loading.tsxis shown. There's no full document reload. - With
cacheComponents: true, the dev overlay shows "blocking route". What does it mean?Correct answer: Uncached data is read outside
<Suspense>and blocks the static shellWith Cache Components, every piece of async work must be either cached via
'use cache'(it goes into the shell) or wrapped in<Suspense>(it streams at request time). Otherwise the whole page would wait for data. This rule is checked in development and at build time. - How does
'use cache: remote'differ from'use cache'?Correct answer: It stores the result in a remote handler shared by all instances, at the cost of network latency
Plain
'use cache'stores entries in process memory (LRU) by default, so in serverless and with multiple instances the cache is short-lived and not shared.remoteuses a handler fromcacheHandlers(Redis, a platform KV) - more reliable but more expensive. Access to request data comes from'use cache: private', notremote.
Combined quizzes with this topic
Questions from several topics at once - just like an interview for a specific role.
Coding tasks
Write your solution right in the browser, and tests check it instantly. Interview classics: debounce, throttle, deepClone, Promise.all, EventEmitter, an LRU cache and more.
Open tasks →