Toward Executable Multi-framework Front-end Code Generation with Self-Correction

Linxiao Li, Haoran Ma, Chenyue Wang, Jiaye Lin, Haochen Sui, Jiechao Gao

TL;DR

MESCoder is a new framework that enables AI to generate fully executable, multi-file front-end projects (React, Vue, Angular) directly from UI screenshots. By breaking down the generation process into a tree-structured task queue and using a self-correcting agent trained via reinforcement learning, it successfully navigates the complex "compilation minefield" that usually breaks one-shot code generation.

What Problem Does This Paper Address?

While Multimodal Large Language Models (MLLMs) have become surprisingly good at generating simple HTML/CSS from a picture, they struggle with modern production-grade frameworks like React, Vue, or Angular.

The gap lies in executability. HTML is forgiving; if you make a mistake, the browser usually just skips it. However, modern frameworks require a strict project structure where files must import and export components correctly to even compile. Current models often fail at this "global consistency"—they might generate a beautiful component but forget to export it or misconfigure the module registration, leading to a project that simply won't run. As shown in the authors' analysis, even top-tier models like GPT-4o and Claude 3.7 face significant failure rates when tasked with these stricter frameworks.

Compilation failure rates of state-of-the-art models across different frameworks.

Methods

The authors introduce MESCoder, which treats project generation as a sequence of localized, manageable decisions rather than a single "all-or-nothing" prompt.

  1. Scaffold Extraction: First, the system extracts a structural "scaffold" from the screenshot—essentially a layout tree that defines which components belong where.
  2. Tree-Structured Generation: Instead of writing one giant file, a Project Agent follows the scaffold to build the project piece-by-piece.
  3. The Action Space: The agent doesn't just "write code." It chooses from a set of high-level actions: CONTINUE (move to the next component), PATCHLOCAL (fix a single file), PATCHCLUSTER (fix errors involving multiple files), ASSEMBLE (wire components together), and FINISH.
  4. Two-Stage Training:
    • Offline Initialization: The model is first trained on "clean" projects and "corrupted" versions of those projects to learn basic repair priors (behavioral cloning).
  5. Online Reinforcement Learning: The agent then practices in a Runtime Sandbox. It receives rewards based on whether the code actually compiles and how closely the rendered result matches the original screenshot.
Figure 2: The two-stage learning process of MESCoder.

Datasets

  • DesignBench: A benchmark of 310 real-world webpage screenshots paired with ground-truth executable projects in React, Vue, and Angular.
  • WebCode2M: A large-scale dataset used to sample 2,000 additional projects for training.
  • Corruption Pipeline: The authors created a custom pipeline to inject realistic errors (syntax bugs, broken imports, etc.) into clean projects to create a robust training set for the self-correction policy.

Key Insights and Ideas

  • Decomposition is Fundamental: The biggest performance jump came from using the scaffold. Breaking a complex UI into a tree of localized tasks prevents the model from being overwhelmed by long-horizon dependencies.
  • "Cluster-Level" vs. "Local" Repair: A key "aha" moment is that many framework errors cannot be fixed by looking at one file in isolation. By allowing the agent to escalate to a PATCHCLUSTER action, it can fix the relationship between files (e.g., an export in File A that doesn't match an import in File B).
  • RL Teaches Selective Escalation: Through reinforcement learning, the model learns to try a local fix first and only escalate to a broader, more "expensive" cluster repair if the local fix fails to resolve the error.

Key Results

MESCoder consistently outperformed one-shot baselines across all frameworks and LLM executors (including GPT-4o, Claude, and Llama 3.2).

  • Executability (CSR): The Compilation Success Rate saw massive gains, particularly in Angular, which is notoriously difficult due to its strict module-wiring constraints. For example, using GPT-4o, MESCoder raised the Angular success rate from 71.1% to 89.2%.
  • Visual Fidelity: By ensuring the code actually runs, the model was able to achieve higher visual similarity (CLIP scores) to the reference screenshots compared to "broken" one-shot attempts.
  • Error Resolution: The framework proved especially effective at resolving "Framework-Specific Engineering" and "Module Dependency" errors, which are the primary killers of automated front-end generation.
CSR gains across different error families, showing the strength of cluster-level repairs.

Limitations and Future Work

While a major step forward, the authors note several areas for improvement:

  • Scaffold Dependency: The system is only as good as the initial layout tree extraction. If the "scaffold" is wrong, the project is likely to fail.
  • Executor Limits: The policy decides what to fix, but the LLM executor still has to write the actual code. If the LLM repeatedly fails to generate a valid patch, the policy can't save it.
  • Beyond Compilation: Currently, the focus is on making the code run and look right. Future work is needed to address "softer" engineering qualities like code maintainability, security, and accessibility.

Summary updated

Abstract

Generating codes from UI screenshots has recently benefited from MLLMs, yet existing methods centered on HTML targets and transfer poorly to multi-frameworks such as React, Vue, and Angular. However, unlike HTML, which does not entail compilation issues, generating executable code in multi-framework settings is more challenging due to framework-specific differences in syntax and failure modes, as well as the need to maintain global consistency across files. To address this problem, we study executable multi-framework front-end code generation and propose MESCoder, a tree-structured self-corrective generation framework. Our method first extracts a structural scaffold from the screenshot and then constructs sub-trees and assembly relations step by step, transforming large project generation into a sequence of localized decisions. On top of this scaffold, we introduce a unified Project Agent that continuously revises its own partial project under runtime sandbox feedback and dynamically chooses between local repair and cluster level repair. For training, we adopt a two-stage strategy that first initializes the policy offline to learn basic multi-framework generation and repair priors, and then refines it with online reinforcement learning to optimize long horizon executability and final page quality. The resulting framework models multi-framework executability as a conditioned project state transition process and improves the stability and quality of complex front end generation through self correction. Experiments show that our method improves executability, while narrowing the visual-fidelity gap to HTML-based generation. Code is available at https://github.com/leo-lilinxiao/MESCoder.
BibTeX
@inproceedings{li2026toward,
  author = {Linxiao Li and Haoran Ma and Chenyue Wang and Jiaye Lin and Haochen Sui and Jiechao Gao},
  title = {{Toward Executable Multi-framework Front-end Code Generation with Self-Correction}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=HRgXvqgzeg},
}
Figure