Q1
Why can blind copy-pasting AI-generated Copilot/Cursor code introduce subtle React infinite re-render loops?
AI assistants often omit memoized callbacks inside useEffect dependencies or recreate inline objects/arrays passed to hooks, triggering setState -> render -> effect -> setState loops unless developers inspect dependency identity carefully.
Q2
How do you validate unreliable LLM JSON outputs reliably inside a Node.js backend?
Use structured output / JSON Schema mode on the OpenAI/Gemini API AND run the parsed payload through Zod runtime validation with fallback retry handling before touching the database.
Q3
What is the security risk of letting an AI feature dynamically build MongoDB queries from natural language?
Prompt injection can trick an LLM into emitting $where, unauthorized tenant IDs, or broad $regex scans. Restrict AI to outputting strictly typed filter enums/JSON parsed server-side with injected authenticated userId scope.
Q4
Why does useEffect run twice in React 18 development StrictMode—and why is fixing it critical rather than disabling StrictMode?
React 18 mounts -> unmounts -> remounts components in dev specifically to expose missing cleanup (AbortController cancellation, WebSocket teardown, duplicate timers) that cause real race conditions in production.
Q5
Why should Vercel/Netlify serverless API routes avoid keeping in-memory rate-limit counters or database pools per request without reuse?
Serverless functions spin up isolated ephemeral containers and cold-start frequently. Use edge Redis (Upstash) for shared rate limits and cache MongoDB mongoose.connect() promises across warm invocations.
Q6
How does AbortController fix race conditions in live React search bars?
When slow earlier requests resolve *after* newer fast keystrokes, older responses overwrite fresh results. Aborting the previous fetch inside useEffect cleanup discards stale responses cleanly.
Q7
Why should Express middleware wrap async route handlers or use Express 5 async error handling?
In Express 4, an uncaught rejected promise inside an async route crashes Node or hangs the HTTP request forever instead of reaching app.use((err, req, res, next) => ...). Always forward errors with next(err).
Q8
How do you stream ChatGPT/Gemini tokens into a React UI smoothly without choking state renders?
Consume ReadableStream chunks via TextDecoder, batch or append into an accumulated message buffer cleanly, and sanitize Markdown/HTML output (e.g., DOMPurify / safe React Markdown) to block XSS from prompt injection.
Q9
What breaks when storing JWT auth tokens in localStorage vs HttpOnly; SameSite=Lax; Secure cookies?
localStorage is readable by any XSS script or third-party tracker injected on the page. HttpOnly cookies cannot be accessed via document.cookie JS while pairing with CSRF protections.
Q10
Why does Mongoose .lean() speed up read-heavy REST endpoints dramatically?
By default Mongoose hydrates full heavy Document instances with change tracking, getters, and .save() methods. .lean() returns plain JavaScript objects, cutting memory allocation and serialization CPU cost.