[{"id":"nextbeadv-001","courseId":"nextjs-backend-advanced","domain":"server-backend","topic":"Closure encryption in Server Actions","prompt":"A page defines an inline Server Action that closes over a value read on the server during render. An interviewer asks what happens to that captured value when the user later submits the form. What is the best answer?","hint":"A closure's values must live somewhere between the render and a POST that comes much later.","source":"https://nextjs.org/docs/app/guides/data-security#closures-and-encryption","interaction":{"type":"single"},"options":[{"id":"a","text":"It stays in server memory and is looked up by the action ID when the form is submitted.","whyNot":"The server keeps no per-render state for actions; captured values have to come back with the request."},{"id":"b","text":"It is sent to the client and back, encrypted by Next.js, so it works but is not a safe place for secrets.","why":"Next.js encrypts closed-over variables with a key generated per build, but the docs advise against relying on encryption alone to hide sensitive values."},{"id":"c","text":"It is sent to the client as plain text in the RSC payload, so anyone can read every captured value.","whyNot":"Next.js encrypts closed-over variables automatically before they reach the client."},{"id":"d","text":"It is recomputed by re-running the page component on the server before the action body runs.","whyNot":"The point of a closure is the snapshot taken at render time; the page is not re-run to rebuild it."}],"answer":"b","explanation":"Values captured by an inline Server Action make a round trip through the client. Next.js encrypts them with a per-build key, but that is a safety net, not a way to hide secrets.","concept":"Values captured by an inline Server Action make a round trip through the client. Next.js encrypts them with a per-build key, but that is a safety net, not a way to hide secrets.","rev":1,"kind":"scenario","code":"export default async function Page() {\n  const version = await getVersion()\n  async function publish() {\n    'use server'\n    if (version !== (await getVersion()))\n      throw new Error('Changed')\n  }\n  return <form action={publish}>…</form>\n}","takeaways":["Captured action values travel through the client, encrypted.","Re-read secrets on the server instead of closing over them."]},{"id":"nextbeadv-002","courseId":"nextjs-backend-advanced","domain":"server-backend","topic":"Sequential dispatch of Server Actions","prompt":"A dashboard fires three independent Server Actions with Promise.all from a Client Component, expecting them to run in parallel. Traces show each request starts only after the previous one finishes. Why, and what is the right fix?","hint":"Look at the client side of the call, not the server.","source":"https://nextjs.org/docs/app/guides/server-actions#sequential-dispatch-on-the-client","interaction":{"type":"single"},"options":[{"id":"a","text":"The server holds a lock per session; move the work into three Route Handlers called with keepalive.","whyNot":"The server does not queue Server Actions; each one runs in its own request as it arrives."},{"id":"b","text":"Promise.all is unsupported for actions; wrap each call in its own startTransition to run them together.","whyNot":"Transitions do not change the client dispatcher, which still sends one action at a time."},{"id":"c","text":"Next.js dispatches actions one at a time per client; do the parallel work inside one action or a Server Component.","why":"The client dispatcher queues actions to keep the re-rendered tree consistent with each result, so parallel work belongs inside a single action, a Server Component or a Route Handler."},{"id":"d","text":"Each action waits for its own revalidation; dropping the revalidatePath calls lets them overlap.","whyNot":"The queueing happens whether or not an action revalidates anything."}],"answer":"c","explanation":"Next.js sends Server Actions from one client one after another. It is a property of the client dispatcher, so parallel work should be done inside one action or fetched elsewhere.","concept":"Next.js sends Server Actions from one client one after another. It is a property of the client dispatcher, so parallel work should be done inside one action or fetched elsewhere.","rev":1,"kind":"scenario","takeaways":["Promise.all over Server Actions still runs them in series.","Parallelise inside one action, not across several."]},{"id":"nextbeadv-003","courseId":"nextjs-backend-advanced","domain":"server-backend","topic":"React taint APIs","prompt":"A team enables experimental.taint and taints each user's secret token with experimental_taintUniqueValue. A lead proposes dropping the Data Access Layer's field filtering, since tainting now protects everything. How should you respond?","hint":"Ask whether the guide treats tainting as a replacement or as a backstop.","source":"https://nextjs.org/docs/app/guides/data-security#tainting","interaction":{"type":"single"},"options":[{"id":"a","text":"Agree: tainted values are encrypted before they can reach the client.","whyNot":"Tainting blocks values from being passed to the client; it doesn't encrypt them."},{"id":"b","text":"Agree: tainting marks the whole module server-only, like import 'server-only'.","whyNot":"server-only guards imports; taint guards specific objects or values."},{"id":"c","text":"Disagree: taint only runs in Client Components, so it protects nothing on the server.","whyNot":"Taint is applied on the server to stop values from reaching Client Components."},{"id":"d","text":"Disagree: taint is an extra layer; keep filtering in the DAL before data reaches render.","why":"The guide calls taint an additional layer of protection and says to still filter and sanitize in the DAL."}],"answer":"d","explanation":"React's taint APIs stop tagged objects or values from being passed to the client, but the guide treats them as an extra layer; DAL filtering stays the main defence.","concept":"React's taint APIs stop tagged objects or values from being passed to the client, but the guide treats them as an extra layer; DAL filtering stays the main defence.","rev":1,"kind":"scenario","takeaways":["Taint is a seatbelt, not the brakes: keep returning minimal DTOs."]},{"id":"nextbeadv-004","courseId":"nextjs-backend-advanced","domain":"server-backend","topic":"Server Actions behind a reverse proxy","prompt":"Pages are served at shop.example.com through a company proxy, but the Next.js server sees requests for a different host. Every Server Action is aborted, while pages and Route Handlers work. What's the documented fix?","hint":"Actions only run when the request's origin matches the host the server sees.","source":"https://nextjs.org/docs/app/guides/data-security#allowed-origins-advanced","interaction":{"type":"single"},"options":[{"id":"a","text":"List the proxy's domain in serverActions.allowedOrigins in the Next.js config.","why":"Actions compare Origin with Host or X-Forwarded-Host and abort on a mismatch; allowedOrigins lists safe origins for proxied setups."},{"id":"b","text":"Switch the forms to method GET, which skips the origin comparison.","whyNot":"Only POST can invoke a Server Action."},{"id":"c","text":"Add a hidden CSRF token field to every form so Next.js accepts it.","whyNot":"Next.js relies on the Origin and Host comparison, not form tokens."},{"id":"d","text":"Set NEXT_SERVER_ACTIONS_ENCRYPTION_KEY so every host shares one key.","whyNot":"That fixes decryption across instances, not an origin mismatch."}],"answer":"a","explanation":"Server Actions abort when Origin doesn't match Host or X-Forwarded-Host. Behind reverse proxies where the domains differ, list safe origins in serverActions.allowedOrigins.","concept":"Server Actions abort when Origin doesn't match Host or X-Forwarded-Host. Behind reverse proxies where the domains differ, list safe origins in serverActions.allowedOrigins.","rev":1,"kind":"scenario","takeaways":["Actions failing only behind a proxy? Check serverActions.allowedOrigins."]},{"id":"nextbeadv-005","courseId":"nextjs-backend-advanced","domain":"server-backend","topic":"Nested short-lived caches","prompt":"A page marked 'use cache' with no cacheLife call renders an imported widget whose own 'use cache' scope calls cacheLife('seconds'). The build now fails while prerendering. Why, and what fixes it?","hint":"Think about which lifetime the outer cache would end up with if nobody set one.","source":"https://nextjs.org/docs/app/api-reference/functions/cacheLife#nested-short-lived-caches","interaction":{"type":"single"},"options":[{"id":"a","text":"cacheLife can't be called inside imported modules; move the call into the page component.","whyNot":"cacheLife works in any cache scope; the issue is the outer scope's implicit lifetime."},{"id":"b","text":"'seconds' isn't a valid profile name, so use 'minutes' or an inline number of seconds.","whyNot":"seconds is one of the built-in preset profiles."},{"id":"c","text":"The short inner lifetime would quietly shorten the outer cache, so set an explicit outer cacheLife.","why":"Without an explicit outer cacheLife, a short-lived nested cache would propagate, so Next.js throws during prerendering."},{"id":"d","text":"Nesting 'use cache' scopes isn't allowed, so remove the directive from the widget.","whyNot":"Nesting is supported, and the docs describe how lifetimes combine."}],"answer":"c","explanation":"A short-lived cache nested in a 'use cache' scope without an explicit cacheLife throws at prerender. Set the outer lifetime explicitly: long to stay static, or short behind Suspense.","concept":"A short-lived cache nested in a 'use cache' scope without an explicit cacheLife throws at prerender. Set the outer lifetime explicitly: long to stay static, or short behind Suspense.","rev":1,"kind":"scenario","takeaways":["Set cacheLife in every 'use cache' scope; implicit lifetimes bite when nested."]}]