NEXT.JS INTERVIEWS
Next.js interview questions
148 questions about Next.js, the way interviewers ask them: 77 to explain, 40 where you say what a real app answers, shows, or prints, and 31 where you write a file of an app. 52 easy, 66 medium, and 30 hard. Every output answer is what Next.js 16.4.3 did when the app was built and run, and every code answer passes its tests.
Every question is free to read. Sign in with Google to see the answers: the short version to say in the interview, why it's true, and what they'll ask next.
148 of 148 questions
Basics & project structure
- What does Next.js add to React, and when would you build without it?
- What's the difference between the App Router and the Pages Router, and can one app use both?
- What does
create-next-appset up by default, and what is each top-level file and folder for? - What do
next dev,next build, andnext starteach do, and why shouldn't you judge speed withnext dev? - One page is a Server Component and the other starts with
"use client". What doesnext buildprint for each? - What happens when a Next.js page first loads, and what's different when you then follow a
<Link>? - Two pages call
console.logwhile they render. What prints duringnext build, and what for each request? - How do you type a page's
paramsandsearchParams, and where doPagePropsandLayoutPropscome from? - A Server Component and a Client Component both read
NEXT_PUBLIC_SHOP_NAMEandSUPPLIER_NAME. What does each show? - Write
redirects()innext.config.tsfor a shop that moved its pages - Move a Pages Router page that uses
getServerSidePropsto the App Router
Routing & navigation
- How do folders in
appbecome routes, and what do[slug],[...slug], and[[...slug]]put inparams? - When do you navigate with
<Link>, and when withrouter.push? - What's the difference between
redirect,permanentRedirect, androuter.replace? - Write a
NavLinkthat marks itself when it points to the current page or its section - What's the difference between a layout and a template, and what renders again when you navigate?
- Which hooks read the URL in Next.js, why are they client-only, and how does a Server Component read the same thing?
- A counter lives in a layout. What does it show after you follow a
<Link>, and then a plain<a>? - Write a tea page that reads its tea from
paramsand the number of cups fromsearchParams - Write previous and next links for the teas layout, with arrow-key shortcuts
- What does
<Link>prefetch, and when? How long does the router keep it, and what happens on Back? - You type a note on a tea page, open another tea, then come back with Back and with a
<Link>. What's kept, and what renders again? - With
generateStaticParamsandnotFound()in a dynamic route, what do/teas/mintand/teas/rooibosanswer?
Special files, errors & advanced routing
- In what order does Next.js nest
layout,template,error,loading,not-found, andpagein one folder, and why does it matter? - How does
error.tsxwork? Why must it be a Client Component, how doresetandretrydiffer, and when do you needglobal-error.tsx? - A tea page has
loading.tsxanderror.tsx, and one tea's stock check throws. What does the server answer, and what does the browser show? - Write
global-error.tsxfor when the root layout itself fails - How is
notFound()different from a URL that matches no route, and where doforbidden()andunauthorized()fit? - Write a
not-found.tsxfor tea pages that suggests teas in stock - What are route groups and private folders, and how do you give the shop and the staff area different root layouts?
- An account layout has an
@ordersslot, and you add a settings page. What doesnext buildsay? - How do parallel routes and intercepting routes give a modal its own URL, and what does a refresh show?
- A tea opens in a modal from the list. What shows after you click Cart, press Back, and reload?
- Add previous and next links to an intercepted tea modal, so one Back still closes it
Server & Client Components
- What is the difference between Server Components and Client Components in Next.js, and how do you choose?
- What does
"use client"actually mark, and does a Client Component only run in the browser? - Can a Client Component render a Server Component? How do you put server-rendered UI inside one?
- A Client Component hides its server-rendered
childrenuntil a click. What runs duringnext build, and what does the click change? - Write a
ReadMoreClient Component that hides server-rendered content until it's opened - A
useStatecomponent without"use client"works inside a Client Component. What happens when a Server Component page renders it too? - What can a Server Component pass as props to a Client Component, and what happens when it passes something it can't?
- An async component is imported into a Client Component instead of being passed in. Does the build pass, and what happens in the browser?
- Use a third-party slide show that needs
useStateand a render function on a Server Component page - Write a context provider that shares the signed-in customer with Client Components, without making the pages wait
- How do you keep server code out of the browser? What do
server-only,client-only, and theNEXT_PUBLIC_prefix do? - Server Components can't use context. How do a layout, a page, and
generateMetadatashare data without loading it three times?
Fetching data & streaming
- How do you fetch data in the App Router, and why don't you need an API route to read your own database?
- What's a request waterfall in a Server Component tree, and how do you avoid one with
Promise.all, sibling components, or preloading? - A teammate rewrites two
awaits as onePromise.all. In what order do the log lines print, before and after? - Write a tea page that fetches three things from an API in parallel and copes with failures and empty answers
- How does streaming work in the App Router, and when do you use
loading.tsxinstead of your own<Suspense>? - A tea page has a cached description, then a slow and a fast
<Suspense>. What's in the first HTML, and what appears in what order? - Is
fetchcached in Next.js 16? What's the difference between request memoization and caching? - Four components fetch the same URL, one with
cache: "no-store"and one with a timeout signal. How many requests reach the API? - What does
connection()do with Cache Components, and when do you need it instead ofcookies(),headers(), or afetch? - When should a Client Component fetch with SWR or React Query, and when should the server fetch the data, or pass a promise to
use()? - Write a review list that reads a Server Component's promise with
use(), and filters it in the browser - Write a data function that asks the database only for what the tea list needs, and returns only those fields
Server Actions, forms & Route Handlers
- What is a Server Action, and what happens when a form calls one?
- Two forms with Server Actions are sent before the page's JavaScript loads. What does the server answer, and what does the next visitor see?
"use server"at the top of a file or inside a function: what's the difference, and what happens to the values an inline action uses?- How should a Server Action report a validation error: return it or throw it?
- Write a Server Action that checks a tasting-box order and returns each field's error to
useActionState - Write a Server Action that adds a tea to a cart kept in a cookie
- How do
useFormStatus,useActionState,useTransition, anduseOptimistichelp while a Server Action runs? - After a Server Action saves a change, how do you update the page:
revalidatePath,updateTag,revalidateTag,refresh, orredirect? - One button's Server Action calls
revalidatePathand the other's doesn't. What does the page show after each click? - When do you use a Server Action, and when a Route Handler?
- A Route Handler exports only
GETandPOST. What doHEAD,OPTIONS, andDELETErequests get? - Write a Route Handler that partner sites can call from the browser, with CORS and a preflight
Rendering: static, dynamic & PPR
- One page reads
cookies()inside<Suspense>and the other reads nothing. Is each route static or dynamic? - What are SSR, SSG, ISR, and CSR, and what do they become in the App Router?
- What makes a page dynamic in Next.js 16, and how does Cache Components change the answer?
- What is Partial Prerendering? What goes into the static shell, and how do the dynamic parts reach the browser?
- A page reads
searchParams, one hasgenerateStaticParams, and two wait forconnection(). What does the route table print? - How does
generateStaticParamswork with Cache Components when it lists every param, some, or none? DoesdynamicParamsstill apply? - The greeting is inside
<Suspense>, but the page awaitsheaders()itself. What doesnext buildsay? generateStaticParamslists only Green tea. What do the first and second visits to/teas/oolongget, and what does the terminal print?- What's the difference between server rendering and hydration, and what does making a page dynamic cost?
- When should a page be fully static, and how do you keep it static as the app grows?
- Split the home page so the tea of the week is prerendered and only its stock is rendered for each request
- Prerender only each category's two best sellers with a
generateStaticParamsthat gets its category from the layout
Caching & revalidation
- The older App Router had four caches. What were they, and what does each become with Cache Components?
- Where can you put
"use cache", and what decides whether two calls share a cached result? - A
"use cache"component logs when it renders. What does the terminal print for four visits to the same page? - What do
stale,revalidate, andexpiremean incacheLife, and how do they give you ISR in the App Router? - Move a data layer from
fetch's cache options to"use cache",cacheLife, andcacheTag - A cached component renders a price that reads
cookies()inside its own<Suspense>. Doesnext buildpass? - What do
"use cache: private"and"use cache: remote"change, and when would you use each instead of"use cache"? - What happens when you call
revalidateTag("teas", "max")? How does Next.js find and refresh everything taggedteas? - A webhook revalidates one price tag with
"max"and another with{ expire: 0 }. What do the next three pages show? - A customer posts a review. Which cached data should the Server Action expire with
updateTag, and which withrevalidateTag? - What does
router.refresh()do, and why doesn't it show new data from a"use cache"function? - Write a
"use cache: remote"cache handler that three self-hosted servers share, tags included
proxy.ts, i18n & multi-tenancy
- What is
proxy.ts, and why did Next.js 16 renamemiddleware.ts? What still works with the old name? proxy.tsredirects/shop, rewrites/menu, and answers/api/stockitself. What does each request get?proxy.tsruns on Node.js. What does that let it do, and what should you still keep out of it?proxy.tshas no matcher and logs each request. What does it print when you open the home page, scroll to a link, and click it?- Fix a
proxy.tsthat sends mixed-case addresses like/Teas/Mint-Teato their lowercase page next.config.tsredirects/shopand rewrites/teamto/staff, andproxy.tsguards/shopand/staff. What gets through?- Why shouldn't
proxy.tsbe your only auth check? What did CVE-2025-29927 show? - How do you build a site in several languages with the App Router, and how is it different from the Pages Router's
i18nconfig? - Keep English pages at
/teasand French ones at/fr/teas, with every page underapp/[lang] - How do you serve many shops, each on its own domain or subdomain, from one Next.js app?
Styling, images, fonts & metadata
- How do you style an App Router app? Where do global CSS, CSS Modules, Tailwind, and CSS-in-JS each fit?
- What does
next/imagedo that a plain<img>doesn't, and which props and settings matter? - Write a custom
next/imageloader that serves every picture from the shop's image CDN - How does
next/fontload a Google font, and why doesn't the text jump when the font arrives? - What are
next/script's loading strategies, and when would you use each? - What is the
publicfolder for, and when should you import a file instead? - An old
public/robots.txtis still there after you addapp/robots.ts. What doesnext buildprint, and what does/robots.txtanswer? - When do you use the
metadataobject and whengenerateMetadata? How does Next.js stream metadata, and what do crawlers get? - The root layout has a title template and the teas section has a layout with a plain title. What title does each page get?
- Tea pages and journal posts each have an
opengraph-image.tsx, and both pages list their slugs. What doesnext buildprint? - Split a 120,000-page marketplace into sitemaps of 50,000 URLs with
generateSitemaps
Auth & security
- What's the difference between authentication and authorization, and where does each check go in an App Router app?
- The staff layout shows customers
Staff only.in place of itschildren. What does Asha get for the orders page, and what prints? - How do you keep a user signed in to a Next.js app: a signed cookie or a database session? Which cookie options matter?
- Write a change-password Server Action that signs the customer out on every other device
- Write the callback Route Handler for "Sign in with Teapot ID", with its
stateand PKCE checks - A Server Action and a Route Handler both save questions. What happens when a page on another site posts to each?
- Does React protect a Next.js app from XSS? Where can a script still get in?
- Which security headers would you add to a Next.js app, and where do you set them?
proxy.tsadds a Content Security Policy with a nonce. Which still works: a static page, one with a static shell, or a dynamic one?- What do React's taint APIs do in a Next.js app, and why aren't they enough on their own?
- How do you cache data that depends on who's signed in, without showing it to someone else?
Performance, testing & deploying
- How do you measure Core Web Vitals in a Next.js app, and what does Next.js already do for LCP, CLS, and INP?
- A Client Component loads
LastBrewwithnext/dynamicandssr: false. What's in the HTML, and what does the browser show? - A page sends too much JavaScript. How do you find what's in it, and how do you make it smaller in Next.js?
- Write the function
useReportWebVitalscalls, so metrics reach your analytics in batches that survive the page closing - How do you test a Next.js app? What can unit tests run, and what needs an end-to-end test?
- What does
output: "export"give you, and what stops working in a static export? - The load balancer checks
/api/health. After staff switch on maintenance, what do/api/healthand/api/readyanswer? - You self-host Next.js in Docker on three servers behind a load balancer. What do the build, the cache, Server Actions, and deployments need?
instrumentation.tshas an asyncregister, andproxy.tsand two pages log too. What does the terminal print, and when?- Write
onRequestErrorininstrumentation.ts, so every server error reaches the error tracker without leaking the visitor's data - What do you check before a Next.js app goes to production?
How Next.js works inside
- What is the RSC payload, and why is it also inside a Next.js page's HTML?
- A Client Component logs when it renders. What does
next startprint for the page's HTML, and for its RSC payload? - How does a
"use client"file become a client reference, and how does the browser find its code? - What are SWC and Turbopack, and what does each do when you build a Next.js app?
- A Server Component, a Client Component, and a Pages Router page each show
React.version. What does each one say? - Walk me through what
next startdoes with a request, from the moment it arrives to the response. - What does the router send when you click a
<Link>, and how does the server know which parts of the page to render? - A layout's basket and a page's stock both log when they render. What prints for a visit, a
<Link>click, a refresh, and Back? - Write
instrumentation-client.tsso the shop's analytics count client-side navigations as page views - How does
"use cache"work under the hood? What does the compiler generate, and what does Next.js store? - Nothing in your code says which parts of a page need a request. How does
next buildfind them with Cache Components?