Five AI-Generated Frontend Bugs That Ship to Production and How to Catch Them
AI coding tools lower the barrier to shipping frontend features, but the bugs they introduce are subtle enough to pass local testing and surface only in production — stale data, infinite loops, and silent failures that erode user trust. A line-by-line review checklist for these five patterns prevents the most common escapes.
Five classes of AI-generated frontend bugs keep surfacing in production: useEffect dependency arrays left empty, CSS Modules class names written as plain strings, TypeScript type safety gutted with `as any`, state updates that read stale closure values, and fetch calls that treat HTTP 4xx/5xx as success. Each pattern stems from the model optimizing for "code that runs" rather than code that is correct under edge conditions.
The fixes are straightforward — complete dependency arrays, functional state updaters, `res.ok` checks, and strict type definitions — but the real defence is a review discipline that treats AI output as a first draft, not a finished feature. ESLint and TypeScript strict mode catch many of these at build time.
Prompting helps: telling the model "no any," "check HTTP status codes," and "consider all reactive dependencies" prevents the worst habits. But state closure bugs and business-logic edge cases still require a human to spot them.
The model's optimisation target is "code that executes without throwing," which explains why it reaches for `as any` and omits `res.ok` — both are the cheapest path to a green runtime, not a correct one.
These five bug classes are not random; they cluster around the places where JavaScript's runtime semantics diverge from intuitive sequential execution: closure scoping, async batching, and the fetch API's refusal to treat server errors as exceptions.
Prompt engineering acts as a lightweight spec: telling the model "no any" or "handle 4xx" is effectively adding a non-functional requirement that the training distribution underweights, and it measurably reduces defect rates.
The advice to review AI code line-by-line is correct but incomplete — the real skill is knowing which lines to scrutinise, and this list of five patterns is a practical starting heuristic for frontend reviewers.