From Visual Mockup to React Page: The Hard Part Is Asset Slicing
This article explains why AI coding tools often produce React pages that look structurally correct but lose the visual quality of the original mockup, and traces the root cause to asset-slicing decisions rather than React code. It introduces a three-layer model (background, content, effects), four rules for deciding what to slice, techniques for handling vignettes, glows, and stacking contexts, practical responsive strategies, and a reusable workflow from annotation and export to generation, calibration, and regression testing. Readers will learn how to plan assets before coding so generated pages move from structural similarity to matching the original look and feel.
1. The Problem: The Page Renders, but the Visual Quality Is Gone
Turning a visually dense product mockup into a working React page sounds like a standard front-end restoration task. The stack is usually React, Next.js, and Tailwind CSS, and the path is familiar: split components, write layout, add styles, wire up interactions. Over the past year or two, AI coding tools with visual understanding have been able to read a screenshot and generate a page skeleton directly, so many people assume this step is already solved.
In real projects, however, the failure mode is predictable when the mockup is not a tidy admin form but a dark-fantasy product homepage with many modules, buildings and characters in the background, and rich layers of light and shadow. The generated result typically shows one symptom: the structure is right, but the feel is wrong. The hero, entry cards, feature sections, character cards, statistics, and bottom story module are all present, and the DOM hierarchy makes sense, yet placing the result next to the original reveals the gap immediately.
The issues fall into five categories:
- Modules feel “scattered”: sections act independently and lack the unifying light source and color palette of the original.
- The background looks “fragmented”: one continuous background is cut into tiled pieces, with color shifts and misalignment at the seams.
- Elements are duplicated: the same decoration is drawn into both the background image and the DOM, producing ghosting and dirty edges.
- Light and dark are out of control: vignettes, overlays, and glows are stacked repeatedly, leaving some areas too dark to read.
- Proportions and hierarchy are distorted: card aspect ratios drift from the original, and text emphasis is lost.
The shared root cause is not how React is written but asset-slicing decisions: which pixels belong to images and which belong to real DOM.
2. Why AI Coding Tools Look Close but Are Wrong
It helps to be clear about the boundaries of these tools. They are good at semantic inference: recognizing “there is a card here,” “there is a button there,” and “the overall style is dark fantasy,” then generating semantic tags, reasonable Tailwind classes, and basic interactions. Their weakness is judging pixel ownership, for three reasons.
First, the training objective favors a “reasonable page” over specified pixels. Models tend to output layouts that follow common design conventions, so when a mockup deliberately breaks normal proportions, the model “corrects” it back to the average.
Second, there is no concept of layers or assets. A design file is layered before export, with background, light effects, overlays, and foreground each on their own layer. The model only sees a flattened bitmap and cannot know which part is a tileable texture and which is a separate asset that needs to preserve an alpha channel.
Third, there are no precise size and coordinate constraints. Fidelity is ultimately decided by pixel error, and natural-language prompts struggle to express hard constraints such as “the spacing here is 13px, not 16px.”
As a result, refining the prompt yields quickly diminishing returns. The effective change is to shift the workflow from “let the model generate the whole page in one shot” to “plan slicing and layering first, then let the model fill in the structure.”
3. Layer Decomposition: Modeling Before Restoration
Before writing code, abstract the mockup into three layers. This is the key to controlling complexity.
Background layer: continuous, non-interactive, responsible for atmosphere. It includes sky, distant buildings, fog, overall color, and vignette. The test is “users will not click it, but it determines the first impression.”
Content layer: carries information and semantics. Titles, body text, buttons, cards, numbers, and icons. The test is “it needs to be selectable, copyable, clickable, or driven by changing data.”
Decoration and effects layer: glows, outlines, particles, glassmorphism, and gradient overlays. The test is “it crosses the boundary between the content layer and the background layer.”
The three layers are implemented in completely different ways: the background layer favors a single full image or a tileable texture; the content layer must be real DOM and text; the decoration layer uses CSS gradients, pseudo-elements, or small images with transparency, depending on the case.
// Layered structure: full background image + real content DOM + separate effects<section className="relative isolate overflow-hidden rounded-3xl">{/* Background layer: one continuous image, never sliced into pieces */}<imgsrc="/scene/hero-bg.webp"alt=""aria-hiddenclassName="absolute inset-0 h-full w-full object-cover"/>{/* Effects layer: vignette and glow as gradients, not baked into the background */}<div className="pointer-events-none absolute inset-0 bg-[radial-gradient(...)]" />{/* Content layer: semantic, selectable, accessible */}<div className="relative z-10 p-8"><h2 className="text-2xl font-semibold text-white">Title</h2><p className="mt-2 text-sm text-white/70">Description text</p><button className="mt-6 rounded-full px-5 py-2">Get started</button></div></section>
4. Four Rules for Slicing Granularity
Slicing is not about being as fine as possible or as coarse as possible. The goal is to match each asset’s rate of change to its form.
- Do not slice anything that changes with content. Text, numbers, and list items are always DOM. Drawing text into an image means giving up accessibility, internationalization, and dynamic data.
- Do slice pure decoration with complex forms. Examples include borders with fine textures, hand-drawn characters, and complex illustrations. Recreating them in CSS costs far more than one image with an alpha channel.
- Do not add new assets for what CSS can express. Rounded corners, shadows, gradients, outlines, and simple glows should be implemented with styles first, which keeps them easy to tune and theme later.
- Prefer a single image for large continuous areas. A background cut into multiple pieces is the main source of fragmentation. To adapt to different screen widths, use
object-coverwith a sensible focal point instead of horizontal tiling.
A practical self-check: will this asset change independently in later iterations? If yes, keep it separate; if no, merge it into a larger whole.
5. Overlays, Vignettes, and Layers: The Real Dividing Line for Fidelity
Most of the immersive quality in the original comes from lighting rather than structure. A common mistake is baking vignettes and glows directly into the background image. Once the container’s aspect ratio changes, the light source drifts and some areas become too dark.
A more reliable approach is to separate lighting from the background and express it as independent layers that can be stacked or switched off:
/* Vignette: its own layer, adapts to the container */.vignette {background: radial-gradient(ellipse at 50% 45%,transparent 40%,rgba(0, 0, 0, 0.55) 100%);}/* Glow: blended on top instead of raising background brightness directly */.glow {background: radial-gradient(circle, rgba(140, 120, 255, 0.35), transparent 70%);mix-blend-mode: screen;}
For layer management, give each module its own stacking context (for example, isolation: isolate) and keep the z-order of background, effects, content, and overlays inside that module. Adjusting one card then does not affect occlusion across the page, which avoids the “the more you fix, the messier it gets” spiral.
6. Balancing Responsiveness and Fidelity
Fixed-size slices will inevitably break on narrow screens. A workable strategy: crop the background proportionally to preserve the composition, reflow the content area with a flexible layout, and set a minimum visible size for decorations while hiding secondary effects on small screens. Do not validate only at desktop width. Cover at least one narrow breakpoint and check whether the seams, the vignette center, and text contrast still hold.
7. A Reusable Workflow
- Annotate: mark the background, content, and effects layers on the mockup, and note the reason for each decision.
- Export: export assets according to the annotations, preferring full images and textures for backgrounds, preserving transparency for decorations, and compressing everything to a modern image format.
- Generate: let the AI coding tool handle only structure, class names, and interactions, and explicitly forbid it from drawing text or complex decorations itself.
- Calibrate: use pixel comparison as the acceptance standard, fix spacing, proportions, and layers one by one, and solve lighting issues back in the independent layers.
- Regress: retest on narrow screens and with different data lengths to confirm fidelity is not only true for a single screenshot.
8. Conclusion
AI can already compress the time spent writing React significantly, but the bottleneck for visual restoration has moved upstream to asset planning and layer judgment. Treating slicing as a design decision that requires modeling, rather than mechanical preparation before coding, is what moves generated results from “structurally similar” to “consistent in look and feel.” In scenarios that require team collaboration and unified asset management, general cloud capabilities such as object storage, content delivery, and monitoring and alerting can host static assets and observe production quality, making the restoration workflow sustainable to maintain.
