LLM Frontend Code Generation in Practice: Diagnosing and Fixing Black Screens

    End-to-end frontend code generation must be judged by whether the generated application runs, not just by whether the code looks complete. This article examines a common failure mode in multi-page applications: pages can be switched, but the main content area shows a black screen. It proposes acceptance criteria centered on runnability and describes six root-cause categories covering mount nodes, routing, global styles, runtime exceptions, static asset paths, and state or permission initialization. It then outlines a systematic workflow—reproduce, isolate by layer, apply a minimal fix, and run regression checks—and provides repair patterns with pseudocode. It closes with evaluation metrics and argues that single-case observations cannot replace repeatable, multi-task testing.

    1. Background: From “Code Can Be Generated” to “Applications Run Reliably”

    As LLM coding assistants move from generating individual functions or components to generating complete multi-page applications, evaluation criteria must evolve accordingly. Initial code that “looks complete” does not mean the application “can run.” In real development, a typical end-to-end failure is that pages can be switched, but the first screen is black: the route entry exists, and the page container responds to clicks, but users cannot see valid content. This can be caused by a missing mount node, an incorrect default route configuration, global style overrides, runtime exceptions that block rendering, static resource loading failures, or state initialization exceptions.

    In one general evaluation, we used role-based prompting, set the task as a frontend development role, and required generation within an isolated project directory of a frontend application containing multiple pages, page switching, basic styles, and interactions. The initial generation took about twenty-plus minutes. After opening the application, pages could be switched, but the main content area appeared black. A repair prompt was then provided, and the issue was located and modified in about one minute. This observation is only used to illustrate the end-to-end generation and debugging process; it cannot be extrapolated into a general performance conclusion. More importantly, a single case cannot prove comprehensive tool capability. A repeatable and verifiable evaluation method must be established.

    2. Evaluation Task Design: Runnability as the Core Acceptance Criterion

    End-to-end code generation evaluation should not focus only on code volume or page count. It should design tasks around “runnable, switchable, and maintainable.” The following dimensions are recommended for acceptance criteria:

    1. Entry usability: After the application starts, the first screen must render key content, not a blank or black screen.
    2. Routing correctness: When switching between multiple pages, paths, default pages, fallback pages, and unmatched path handling must meet expectations.
    3. Runtime stability: The browser console should not contain uncaught exceptions that block rendering. Asynchronous data errors should have fallback displays.
    4. Style visibility: Text, buttons, container backgrounds, and foreground colors must have sufficient contrast. Content must not exist but be invisible.
    5. Resource integrity: Static resource paths for scripts, styles, and images must be correct. After build output is deployed, it must not fail because of differences between relative and absolute paths.
    6. Maintainability: The directory structure should be clear. Page rendering, state management, and error handling boundaries should be explicit, making later repairs easier.
    7. Repair loop capability: After a failure occurs, can the root cause be located from the symptoms, a minimal change be made, and regression verification be completed?

    During evaluation, complete observation information should also be recorded: operation steps, entry URL, console errors, network request status, DOM snapshots, key computed style values, and differences before and after repair. Only when “symptom—root cause—change—regression” forms a closed loop does the evaluation have engineering reference value.

    3. Root-Cause Model for Black-Screen Failures

    A “black screen” is not equivalent to a “coding problem.” It is often a presentation-layer symptom that may correspond to multiple layers. Common root causes can be summarized into six categories.

    1. Missing mount node or incorrect selector

    A frontend application usually needs to mount page content to a root node. If the root node does not exist, the selector is misspelled, the script executes before the DOM is ready, or the root node is hidden by styles, the rendering logic may not report an error, but the content cannot be displayed. For this type of issue, check the entry script, root node identifier, and script loading position first.

    2. Abnormal default route and page registration

    The ability to switch pages shows that the routing system is partially working, but a black first screen may mean that the default path does not match a valid page, the home component is not registered, or redirect rules are missing. For multi-page applications, the default rendering logic for the “/” path should be explicit, and a fallback page should be provided for unmatched paths to avoid blank screens.

    3. Global style overrides causing “content exists but is invisible”

    This is a category that is easily misdiagnosed as a rendering failure. For example, the global background color and text color are the same, container opacity is 0, visibility is hidden, or the layer is covered, all of which can cause a visual black screen. During troubleshooting, check whether the DOM exists, whether element dimensions are normal, and the computed values for color, opacity, visibility, and layering.

    Counterexample:

    1. /* Counterexample: content exists but is invisible */
    2. html, body {
    3. background: #000;
    4. color: #000;
    5. }
    6. .app-root {
    7. opacity: 0;
    8. }

    The above styles can make the page appear black, while the DOM may already be rendered. When fixing, restore reasonable foreground-background contrast and remove incorrect opacity or hiding rules, rather than blindly rewriting business logic.

    4. Runtime exceptions blocking rendering

    Uncaught exceptions, null access, unhandled asynchronous data, and state initialization failures can all interrupt the render function. If an error boundary is missing, users can only see a blank area. Use browser developer tools to inspect console errors and call stacks, and add page-level error fallback displays.

    5. Build output and static asset path errors

    A common reason an application runs locally but shows a black screen after deployment is incorrect static asset paths, where script or style requests return 404. During troubleshooting, check resource status in the network panel, the build output directory, base path configuration, and subpath differences in the deployment environment.

    6. State and permission initialization exceptions

    Some applications depend on user state, permission information, or remote configuration on the first screen. If the initialization state is empty, permission checks block the page without a prompt, and the result can also appear as a black screen. For such issues, add loading, empty, no-permission, and failure states to prevent all exceptions from degrading into blank screens.

    4. Systematic Diagnosis Workflow

    When facing black-screen issues, proceed in the order of “reproduce first, then isolate by layer, then apply a minimal fix, and finally run regression.”

    Step 1: Stable reproduction. Record the entry point, operation steps, browser type, whether it occurs only on first load, and whether it is related to caching. Save console errors, network requests, and DOM snapshots. Avoid guessing from screenshots alone.

    Step 2: Layered investigation. First confirm whether the root node exists, then confirm whether the render function executes, and then check route matching results, style visibility, and resource loading status. Temporarily simplify the page, keep the minimal mount logic, and use bisection to isolate the effects of styles, routing, or asynchronous logic.

    Step 3: Minimal fix. Keep the fix as small as possible and avoid rewriting the entire page at once. If the root cause is a missing default route, add the default page. If the root cause is a style override, correct the visibility rules. If the root cause is an uncaught exception, add an error boundary and logging.

    Step 4: Regression verification. After the fix, traverse all pages and check page switching, refresh, direct access to child paths, empty data, and error data scenarios. Confirm that no new black screens or console errors have been introduced.

    5. Repair Strategies and Illustrative Code

    During the generation stage, the application should already be required to have basic fault tolerance. For example, when the mount node is missing, show a clear error; when a route is unmatched, fall back to the home page; when rendering throws an exception, show a readable error panel instead of silently displaying a black screen.

    1. // Pseudocode for general page rendering and error fallback
    2. const routes = {
    3. '/': renderHome,
    4. '/list': renderList,
    5. '/detail': renderDetail
    6. };
    7. function navigate(path) {
    8. const root = document.querySelector('#app-root');
    9. if (!root) {
    10. showFatal('Application mount node is missing. Check the entry page.');
    11. return;
    12. }
    13. const render = routes[path] || routes['/'];
    14. try {
    15. root.innerHTML = '';
    16. render(root);
    17. } catch (error) {
    18. console.error('[render-error]', error);
    19. root.innerHTML = '<div class="error-panel">Page failed to load. Return to the home page or try again later.</div>';
    20. }
    21. }
    22. function showFatal(message) {
    23. document.body.innerHTML = '<div class="fatal-panel">' + message + '</div>';
    24. }

    This example reflects three principles: the entry node must be validated; the default route must have a fallback; and rendering exceptions must be observable and displayable. For style issues, visibility checks for key elements can be added during the acceptance stage, such as confirming that text color differs from background color, container dimensions are non-zero, and opacity and visibility are normal.

    6. Evaluation Metrics and Conclusion

    Evaluation metrics should be divided into functional correctness, runtime stability, repair efficiency, maintainability, and explanation quality. Functional correctness focuses on whether pages are complete and routing is accurate. Runtime stability focuses on console errors, resource failures, and exception fallbacks. Repair efficiency focuses on the number of rounds and time from prompt to fix. Maintainability focuses on structure, naming, and boundary handling. Explanation quality focuses on whether the tool can explain the root cause and the impact of changes.

    It should be emphasized that a single “quick fix” can only serve as an observation sample and cannot replace systematic evaluation. More reliable conclusions should come from multi-task, multi-round, repeatable test sets that cover initial generation, fault injection, repair verification, and regression checks. For developers, when choosing or using LLM coding assistants, the key focus should be end-to-end closed-loop capability: whether the tool can generate a runnable application, locate real faults, provide a minimal change, and complete regression verification. Only when evaluation moves from “does the code look right” to “does the application run reliably” does LLM frontend code generation truly have engineering value.