Interview questions with answers
Next.js 16+ interview questions and answers
App Router, Server Components, Cache Components, proxy.ts and Turbopack. Open any question to read its model answer; the multiple-choice set marks the right option and explains it.
- Subjective
- 30
- Objective
- 30
Subjective questions 30
1What are React Server Components and how does Next.js use them?Asked almost every time
In the App Router every component is a Server Component by default: it renders on the server, can be async, reads data directly (database, file system, secrets), and sends no JavaScript to the browser. Components that need state, effects or browser APIs opt in with "use client". Server Components can render Client Components and pass them serialisable props, which keeps bundles small.
2What is new in Next.js 16?Asked almost every time
Turbopack is the default bundler for dev and build. Cache Components make caching explicit with the "use cache" directive, cacheLife and cacheTag, alongside Partial Prerendering. middleware.ts is renamed proxy.ts. New cache APIs updateTag() and refresh() join revalidateTag(), which now takes a cache-life profile. React Compiler support is stable, routing got layout deduplication and incremental prefetching, and it ships with React 19.2.
3Explain how caching works with Cache Components.Asked almost every time
With cacheComponents enabled, data fetching is dynamic by default and nothing is cached unless you say so. Mark a function, component or whole route with "use cache" to cache its output; set how long with cacheLife('hours') and label it with cacheTag('products'). Dynamic parts wrapped in <Suspense> stream in, while cached parts are part of the prerendered shell (Partial Prerendering).
4What are Server Actions and how do you use them safely?Asked almost every time
Async functions marked "use server" that run on the server and can be called from forms (<form action={createPost}>) or client code. They handle mutations without writing API routes, and work with useActionState and progressive enhancement. Treat them like public endpoints: validate input (for example with Zod), check authentication and authorisation inside each action, and revalidate or update caches afterwards.
5How do you fetch data in Server Components?Asked almost every time
Make the component async and await the data directly (fetch, an ORM, an SDK), so no client-side waterfall or API route is needed. Start independent requests in parallel with Promise.all, wrap slow parts in <Suspense> to stream them, and mark reusable cached functions with 'use cache'.
6When do you need a Client Component?Asked almost every time
When the UI uses state, effects, event handlers, refs, browser APIs or client-only libraries. Mark the module with 'use client' and keep it as small as possible, at the leaves of the tree, passing Server Components to it as children when needed.
7How do you handle authentication in the App Router?Asked almost every time
Check the session close to the data: in Server Components, Route Handlers and every Server Action, using a data access layer that verifies the user. proxy.ts can do optimistic redirects, but never rely on it alone. Store sessions in secure httpOnly cookies.
8How do you avoid client-server data waterfalls?Asked almost every time
Fetch in Server Components near the root of a segment, start independent requests together, preload data with functions called before awaiting, pass promises down to children that use() them, and stream slower parts with Suspense rather than chaining sequential awaits.
9How does routing work in the App Router?Very often asked
Folders in app/ define URL segments; page.tsx makes a segment routable. layout.tsx wraps pages and persists across navigation, loading.tsx adds a Suspense fallback, error.tsx an error boundary, not-found.tsx a 404. Dynamic segments use [id], catch-all [...slug], route groups (group) organise without changing URLs, and parallel (@slot) and intercepting routes handle modals and dashboards.
10What is proxy.ts and when do you use it?Very often asked
In Next.js 16 proxy.ts (formerly middleware) runs before a request is handled, on the Node.js runtime. Use it for redirects, rewrites, setting headers or cookies, and light checks such as redirecting signed-out users. Keep it fast and do not rely on it alone for authorisation; check access again where the data is read.
11How do revalidateTag, updateTag and refresh differ?Very often asked
revalidateTag(tag, 'max') marks tagged cache entries stale with stale-while-revalidate behaviour, good for content that can be slightly behind (calling it without a profile is deprecated). updateTag(tag) (Server Actions only) expires the entry and reads fresh data in the same request, giving read-your-writes after a mutation. refresh(), callable only inside a Server Action, refreshes the client router so the page re-renders with fresh uncached data, without touching cached entries.
12What changed about params and searchParams?Very often asked
They are Promises: in pages, layouts and route handlers you await params (or use React's use() in a client component). The same applies to cookies(), headers() and draftMode(). This lets Next.js know which parts are dynamic and prerender the rest.
13How do you optimise images and fonts?Very often asked
next/image resizes, serves modern formats such as WebP/AVIF, lazy-loads and reserves space to prevent layout shift; remote hosts are allowed with images.remotePatterns. next/font downloads Google or local fonts at build time and self-hosts them, with no external request and automatic fallback metrics.
14How do streaming and Suspense improve performance?Very often asked
The server sends the page shell immediately and streams slower parts as they resolve, each wrapped in <Suspense> (or using loading.tsx). Users see content sooner, and a slow query no longer blocks the whole page.
15What are parallel and intercepting routes?Very often asked
Parallel routes render several pages in one layout through named slots (@modal, @feed), each with its own loading and error states. Intercepting routes ((.)photo/[id]) show a route inside the current layout, such as a modal, while a direct visit renders the full page.
16How do error.tsx and not-found.tsx work?Very often asked
error.tsx is a Client Component error boundary for a segment. It receives the error and a retry() function (stable since 16.3) that re-fetches and re-renders the segment; reset() still exists for clearing the error without re-fetching. not-found.tsx renders when notFound() is called or a route does not match. global-error.tsx catches errors in the root layout.
17How do you validate input in Server Actions?Very often asked
Treat every action as a public endpoint: parse FormData or arguments with a schema (Zod), check authentication and authorisation, return structured errors for useActionState, and never trust hidden fields or IDs from the client.
18How do you optimise bundle size in Next.js?Very often asked
Keep heavy code in Server Components, lazy-load client-only widgets with next/dynamic, import only what you use from large libraries, analyse bundles, avoid putting providers that pull big dependencies in the root layout, and use next/font and next/image.
19What are layouts vs. templates?Very often asked
A layout.tsx wraps a segment and keeps its state across navigations between child pages. A template.tsx is similar but remounts on each navigation, useful for enter animations or resetting state.
20How does <Link> prefetching work?Very often asked
Links in the viewport prefetch the route's static parts (and in production the loading state for dynamic routes), so navigation feels instant. Client-side navigation keeps shared layouts mounted and only renders the changed segments.
21What are Route Handlers?Often asked
Files named route.ts that export HTTP method functions (GET, POST, …) using the Web Request and Response APIs. Use them for webhooks, public APIs or anything called by non-React clients; for your own forms, Server Actions are usually simpler.
22How do you handle metadata and SEO?Often asked
Export a metadata object or a generateMetadata function from a layout or page for titles, descriptions, Open Graph and robots. Add sitemap.ts, robots.ts and opengraph-image.tsx files for generated assets, and render meaningful HTML on the server.
23Static, dynamic or partially prerendered: how is a route rendered?Often asked
Content that does not depend on the request is prerendered at build time. Anything reading request data (cookies, headers, searchParams) or uncached data renders per request. With Partial Prerendering, one route mixes both: a static shell served instantly, with dynamic holes streamed in through Suspense.
24How do environment variables work in Next.js?Often asked
Variables in .env files are available on the server. Only those prefixed with NEXT_PUBLIC_ are inlined into client bundles at build time, so never prefix secrets. Changing a public variable requires a rebuild.
25What does generateStaticParams do?Often asked
It returns the list of dynamic params to prerender at build time for routes like /blog/[slug]. Other params can be rendered on demand and cached, depending on configuration.
26How do you handle internationalisation?Often asked
Use a [lang] segment, detect the preferred locale in proxy.ts and redirect, load dictionaries in Server Components, and set generateStaticParams for supported locales and alternates in metadata.
27How do you use after()?Often asked
after() schedules work (logging, analytics, cache warming) to run after the response is sent, so it does not delay the user. It works in Server Components, Server Actions, Route Handlers and proxy.
28How do you build an API with Route Handlers?Often asked
Create route.ts files exporting functions named after HTTP methods (GET, POST) that take a Request and return a Response. Validate input, check auth, and use them for webhooks or external clients; for your own UI, Server Actions are often simpler.
29How do you deploy Next.js outside Vercel?Sometimes asked
Run next build and next start on any Node.js server, or use output: 'standalone' for a small Docker image. Configure a shared cache handler if you run several instances, serve static assets through a CDN, and set up image optimisation (sharp is used automatically).
30How do you analyse and debug Next.js performance?Sometimes asked
Use the bundle analyzer, React DevTools Profiler, the Next.js dev overlay and server logs, measure Core Web Vitals with useReportWebVitals or real-user monitoring, and check which routes are static or dynamic in the build output.
Objective questions 30
1In the App Router, components are… by default.Asked almost every time
Why: You opt into the client with "use client".
2Which file did Next.js 16 introduce to replace middleware.ts?Asked almost every time
Why: Middleware was renamed proxy in Next.js 16.
3Which directive caches a function or component with Cache Components?Asked almost every time
Why: "use cache" marks output to be cached, tuned with cacheLife and cacheTag.
4What is the default bundler in Next.js 16?Asked almost every time
Why: Turbopack is the default for both next dev and next build.
5Which directive marks a Client Component?Asked almost every time
Why: It marks the client boundary.
6Which function renders the closest not-found UI?Asked almost every time
Why: It renders not-found.tsx.
7Which env variables reach the browser?Asked almost every time
Why: They are inlined at build time.
8Which file defines UI shared by a segment and its children that persists across navigation?Very often asked
Why: Layouts keep their state between navigations; templates remount.
9How do you read params in a Next.js 16 page?Very often asked
Why: params is a Promise and must be awaited.
10Which API gives read-your-own-writes after a Server Action mutation?Very often asked
Why: updateTag expires and refreshes the tagged data within the same request.
11Which file shows a fallback while a segment loads?Very often asked
Why: loading.tsx wraps the segment in Suspense.
12Where must Server Actions check authorisation?Very often asked
Why: Actions are reachable endpoints, so they must check access themselves.
13Which file catches errors in the root layout?Very often asked
Why: It replaces the root layout when active.
14What does a folder named @modal create?Very often asked
Why: Slots render in the parent layout.
15Which file remounts on every navigation?Very often asked
Why: Layouts persist; templates remount.
16Which function prerenders dynamic routes at build time?Very often asked
Why: It returns the params to build.
17Which API runs work after the response is sent?Very often asked
Why: Good for logging and analytics.
18How should independent fetches in a Server Component run?Very often asked
Why: This avoids waterfalls.
19What does a folder named (marketing) do?Often asked
Why: Parentheses mark a route group.
20Which component optimises images automatically?Often asked
Why: It resizes, converts formats and lazy-loads.
21What do [...slug] folders match?Often asked
Why: A catch-all segment captures the rest of the path as an array.
22Which function sets how long a cached entry lives?Often asked
Why: cacheLife takes a profile such as 'minutes', 'hours' or 'days'.
23What does (.)photo/[id] do?Often asked
Why: Used for modals over the current page.
24What exports does a route.ts use?Often asked
Why: GET, POST and so on.
25Which helper lazy-loads a client component?Often asked
Why: It splits the code into a chunk.
26What do Links in the viewport do in production?Often asked
Why: Navigation feels instant.
27Which file shows when a slot has no matching route on reload?Often asked
Why: Parallel routes need a fallback.
28Which next.config option creates a minimal server bundle for Docker?Sometimes asked
Why: Standalone output copies only the files needed to run.
29Which hook reports Core Web Vitals?Sometimes asked
Why: Send them to analytics.
30Where should session tokens be stored?Sometimes asked
Why: JavaScript cannot read them.
Track what you have practised and search every bank in your dashboard.
Start learning