Evaluating Frontend Generation in LLMs: Common Pitfalls and Fixes

    This article evaluates the frontend page generation capabilities of large language models through two complex scenarios: a retro print-style magazine layout and a deep-space mission visualization. It shows that visual fidelity and first-screen appearance usually pass, while state consistency, responsive layout, and maintainability are where models fail. The article breaks down prompt constraints for typography, state machine patterns for navigation, data-driven animation architecture, interaction strategies, performance budgets, a five-dimension scoring rubric, and a standard iteration workflow for fixing generated frontend code.

    1. Background: Why “Generating a Page” Is Not the Same as “Delivering a Page”

    Over the past year, code generation models have made clear progress on single-file page output. However, real engineering work demands far more usability than a demo requires. Consider a typical evaluation with two high-complexity goals: first, replicating the layout language of a 1990s print magazine; second, building a deep-space flight mission visualization with a multi-stage timeline, a telemetry panel, and camera switching. Both share high visual demands, many states, and long interaction chains—exactly the conditions that expose a model’s weaknesses on both the aesthetic and engineering ends.

    The evaluation conclusion fits in one sentence: style transfer and first-screen appearance usually meet the bar, while the problems concentrate in state consistency, edge-case layout, and maintainability. This article abstracts these two scenarios into general capability dimensions and offers actionable improvement methods.

    2. Scenario 1: Implementing a Retro Print-Style Page and Its Typical Defects

    2.1 Prompts Should Explicitly Constrain the Typography System

    A retro style is not “add a filter”—it is a complete set of layout rules. A reusable prompt skeleton looks like this (illustrative):

    1. Goal: Simulate a 1990s print magazine
    2. Fonts: High-contrast serif for headings, monospace for body
    3. Grid: Multi-column with unequal widths, asymmetric whitespace allowed
    4. Bleed: Main heading overflows the viewport edge to mimic print bleed
    5. Images: Low-saturation sepia tones with light noise overlay
    6. Page turn: Page transitions use a page-flip effect
    7. Navigation: Presented as a table of contents, entries numbered 01/02/03, scale on hover
    8. Footer: Copyright-column style with a fictional issue number
    9. Background: Paper texture

    The key is to decompose “style” into five categories of verifiable constraints—fonts, grid, color, motion, and component semantics—rather than vaguely describing “retro.”

    2.2 Frequent Defects and Root Causes

    • The first-screen table of contents covers the body text: this is essentially a conflict between stacking contexts and positioning strategy. The fix is to assign the table of contents its own layer and reserve a safe area for the body, for example by managing offsets with CSS variables.
    • Garbled text appears after collapsing the table of contents: this is usually caused by conditional rendering competing with transition animations, where nodes are reused or unmounted before the animation ends. It should be changed to a “state machine + unidirectional data flow,” with DOM cleanup driven by animation-end events.
    • The asymmetric grid collapses: unequal column widths tend to overlap on narrow screens, so the grid needs a minimum usable width and a breakpoint that degrades to a single column.

    Illustrative state definition:

    1. const nav = { open: true, phase: 'idle' }; // phase: idle | opening | closing
    2. function toggleNav(state) {
    3. if (state.phase !== 'idle') return state; // ignore repeated triggers during animation
    4. return { open: !state.open, phase: state.open ? 'closing' : 'opening' };
    5. }

    3. Scenario 2: Engineering Breakdown of a Deep-Space Mission Visualization Animation

    3.1 Split the Mission into Data and View Layers

    For this kind of requirement, model the mission phases as data first, then let the view consume them, avoiding logic hard-coded into the animation. Phases can be abstracted as: orbit insertion, Earth orbit check, trans-lunar injection, cruise, lunar flyby, free return, and reentry and splashdown. Each phase includes a time interval, key events, and a telemetry baseline.

    1. const phases = [
    2. { id: 'orbit', label: 'Orbit insertion and check', events: ['Separation', 'System self-test'] },
    3. { id: 'tli', label: 'Trans-lunar injection', events: ['Ignition', 'Final correction'] },
    4. { id: 'flyby', label: 'Lunar flyby', events: ['Closest approach', 'Communication blackout'] },
    5. { id: 'return', label: 'Free return', events: ['Mid-course correction'] },
    6. { id: 'reentry', label: 'Reentry and splashdown', events: ['Blackout', 'Parachute deploy'] }
    7. ];

    3.2 Interaction Checklist and Implementation Strategy

    • Timeline scrubbing: use a normalized progress t∈[0,1] mapped to phases and interpolation, so any jump is reversible.
    • Phase jumps: buttons only modify t and never operate the animation directly, ensuring a single source of truth.
    • Telemetry panel: velocity, distance, fuel, and others are derived from t; independent accumulation is forbidden to avoid drift.
    • Camera switching: the orbital view, spacecraft view, and lunar-surface view share the same scene graph and only switch the observation matrix.
    • Trajectory visibility and event captions: managed by layer groups; event annotations support both hover and click triggers.
    • Bilingual presentation: English labels with Chinese descriptions, separating copy from logic for unified maintenance.

    3.3 Balancing Visuals and Performance

    Cyber-style visuals often come with glow, scan lines, and particle trails, which are expensive. Recommendations: make particle count adaptive to viewport area; use post-processing for glow instead of stacking many semi-transparent layers; bake the static starfield once; and automatically degrade on low-end devices by disabling depth of field and trails.

    4. General Evaluation Dimensions and Scoring Suggestions

    Evaluate generated results across five dimensions: visual fidelity, interaction completeness, state consistency, responsive robustness, and maintainability. Score each dimension from 0 to 2, for a total of 10 points. In practice, visuals and first-screen appearance usually score high, while state consistency and responsiveness lose the most points. Archiving failure cases into four categories—layout stacking, animation timing, data derivation, and performance budget—can significantly improve iteration efficiency.

    5. Standard Workflow for Iterative Fixes

    1. Reproduce and minimize: compress the problem to a single component and a single state.
    2. Locate the layer: determine whether it is a CSS stacking issue, a rendering-timing issue, or a data-derivation error.
    3. Refactor to unidirectional flow: introduce an explicit state machine and forbid direct DOM changes in multiple places.
    4. Regression verification: cover edge cases such as rapid repeated clicks, narrow screens, and mid-animation jumps.
    5. Performance gatekeeping: set frame-rate and memory budgets, and degrade automatically when thresholds are exceeded.

    6. Deployment Suggestions on a Cloud Platform

    To productize this kind of capability, you can rely on Baidu AI Cloud’s object storage to host static assets, a content delivery network to accelerate page loading, log services and monitoring alerts to track frontend exceptions, and a container platform to run model inference services, with a message queue for peak shaving. On the model side, it is recommended to adopt a closed loop of “generation + static checks + automated regression,” turning prompt templates, evaluation sets, and fix strategies into reusable assets.

    7. Conclusion

    The core tension in complex frontend generation is between aesthetic freedom and engineering determinism. Decomposing style into constraints, interactions into states, and performance into budgets is what moves generated results from “looks right” to “runs reliably.”