Question presented to candidate: "A user reports that 'Add to cart' sometimes fails, and our error tracker also shows a hydration error on the product page. Using what Next.js 16.2 added for debugging, how do you find out which Server Function was called with what, why it failed, and exactly which text did not match during hydration?"
What a strong answer should cover:
- Server Function logging (16.2):
next devprints each call under its request with the function name, arguments, duration and file, on by default and controlled bylogging.serverFunctions. - Browser-to-terminal forwarding:
logging.browserToTerminal(moved out ofexperimentalin 16.2) sends browser warnings and errors to the dev terminal by default, all output withtrue. - Hydration errors show a server/client diff (
+client,-server) in the overlay and terminal; common causes aretypeof windowbranches,Date.now(), locale formatting and invalid nesting. - Fixes: render the same output on both sides, move client-only values into
useEffector a client-only component, usesuppressHydrationWarningonly for a single unavoidable text node. - Production: messages are hidden from the browser (a digest), so correlate with server logs;
next start --inspect(16.2) attaches a debugger to the production server.
Clarifying questions expected:
- "Does it reproduce in
next dev?" β the rich logs and diffs are development features. - "Is the failure on the server or in the browser?" β the terminal shows both now.
Code / implementation expected: Optional β the logging config and a fixed hydration-safe component.