GenClass is open source.Star on GitHub

How to fix a blank page in production.

A page that is blank in production but fine on your machine usually means the JavaScript that draws it failed: it threw before the first render, or the browser never loaded or ran the bundle. Open the live page with DevTools and find the first error in the Console or the first failed script in the Network panel. That error points to the fix, such as an error boundary for a render error or the right base path for a script that returns 404.

Find the first error

Debug the live site, because the dev server serves different files and headers. Open DevTools, tick Preserve log and Disable cache in the Network panel, reload, and look in three places:

  1. The Console. The first red error matters most; later ones often follow from it.
  2. The Network panel, filtered to JS: a script that returned 404, came back as HTML or was blocked.
  3. View page source next to Elements: an empty <div id="root"></div> in both means nothing rendered.

React's white screen of death: an error while rendering

By default, an error thrown during rendering makes React remove its UI, so one component reading a field of undefined data empties the page. Wrap the app in an error boundary with a fallback:

import { Component } from "react";
import { createRoot } from "react-dom/client";
import App from "./App";

class ErrorBoundary extends Component {
  state = { error: null };
  static getDerivedStateFromError(error) {
    return { error };
  }
  componentDidCatch(error, info) {
    console.error(error, info.componentStack); // or send it to your error tracker
  }
  render() {
    if (!this.state.error) return this.props.children;
    return (
      <p role="alert">
        This page did not load. <button onClick={() => location.reload()}>Reload</button>
      </p>
    );
  }
}

createRoot(document.getElementById("root")).render(
  <ErrorBoundary><App /></ErrorBoundary>
);

A boundary must be a class (or come from react-error-boundary). It misses errors in event handlers, async code, server rendering and code that runs before React renders, such as a module that crashes on import. React 19's createRoot takes an onUncaughtError option to log render errors no boundary caught.

Blank after a deploy: files that no longer exist

A tab opened before your deploy keeps running the old code. When it lazy-loads a route, it asks for an old hashed file; if the deploy deleted it, the import fails: webpack throws a ChunkLoadError ("Loading chunk 42 failed"), and Vite's docs describe the same failure. React.lazy passes it to the nearest error boundary; with none, the page goes blank.

  1. Keep the previous deploy's hashed files online for a while. Next.js's self-hosting guide describes this for its immutable static assets: keep adding them to the same folder or CDN bucket.
  2. Serve index.html with Cache-Control: no-cache, as Vite's docs advise.
  3. Reload once: Vite emits vite:preloadError on window, and event.preventDefault() stops the throw. A timestamp prevents a loop:
window.addEventListener("vite:preloadError", (event) => {
  const last = Number(sessionStorage.getItem("reloaded-at"));
  if (Date.now() - last < 30_000) return; // reloaded already: let the error through
  sessionStorage.setItem("reloaded-at", String(Date.now()));
  event.preventDefault();
  window.location.reload();
});

With webpack, check error.name === "ChunkLoadError" in your boundary. In Next.js, deploymentId turns navigation in a tab from an older deployment into a full page reload.

Blank after a build: the wrong base path

By default most builds point at their files from the site root, with paths such as /assets/index-[hash].js. Served from a subfolder, like a GitHub Pages project site under /repo/, those requests return 404. Set Vite's base or Next.js's basePath (inlined at build time, so a change needs a rebuild):

// vite.config.js (React, Vue or Svelte on Vite)
export default { base: "/repo/" };

// next.config.js
module.exports = { basePath: "/repo" };

In webpack the option is output.publicPath, in Angular ng build --base-href, in Create React App the homepage field. If your host answers every unknown path with index.html, a missing .js file comes back as HTML. A module script then fails the browser's strict MIME type check, and a classic script stops with Unexpected token '<'.

A Content Security Policy that blocks the bundle

A CSP header that only production sends can block your scripts. script-src lists where scripts may load from; inline scripts need 'unsafe-inline', a nonce or a matching hash. Browsers log the violation in the console. Allow your bundle's origin or use nonces (Vite's html.cspNonce adds a placeholder your server must replace per request), and test with Content-Security-Policy-Report-Only, which reports without blocking.

An environment variable that was undefined at build time

Vite swaps import.meta.env values in at build time and exposes only VITE_ names, and Next.js inlines NEXT_PUBLIC_ variables during next build. A key only in your git-ignored .env.local is undefined in a CI build, and a client library that gets it at import time can throw before React renders. Fail the build instead:

// vite.config.js
import { defineConfig, loadEnv } from "vite";

export default defineConfig(({ command, mode }) => {
  if (command === "build") {
    const env = loadEnv(mode, process.cwd()); // .env files, plus VITE_ variables set in CI
    for (const name of ["VITE_API_URL"]) {
      if (!env[name]) throw new Error(`${name} is not set for this ${mode} build`);
    }
  }
  return { /* the rest of your config */ };
});

Syntax an older browser cannot run

If a browser cannot parse the bundle, none of it runs: per the language spec, a module with an early error is never initialized. Vite's default build targets browsers in Baseline Widely Available and adds no polyfills; @vitejs/plugin-legacy builds for older ones. Next.js reads a browserslist entry, injects a few polyfills and leaves the rest to you.

Next.js and hydration: content that flashes, then goes white

Server-rendered HTML arrives with content, so text that flashes and then disappears usually means code in the browser threw. React's docs list hydration error causes such as typeof window checks and browser-only APIs like window.matchMedia in rendering logic. React recovers from some hydration errors, but a throw during a browser render is an ordinary render error. With no boundary, the App Router shows Next.js's built-in error page ("Application error: a client-side exception has occurred" up to 16.1, "This page couldn't load" from 16.2). Add error.js files and a global-error.js.

Blank with no error in the console

Content in Elements but not on screen means CSS hides it, such as a fade-in still at opacity: 0 because its script never ran; check the root's computed opacity, visibility, display and height. An empty root with a clean console points to a component returning null on a missing value, or a catch that swallows an error. A page stuck on a spinner points to a request that never resolves.

How to detect a blank page in production

An error tracker imported by your bundle never starts when the bundle fails. Put a few lines in index.html, before the bundle, to report failed scripts and a root still empty after load with sendBeacon. Script load errors do not bubble, so listen on window in the capture phase:

<script>
  const report = (kind, detail) =>
    navigator.sendBeacon("/api/client-errors", JSON.stringify({ kind, detail, page: location.pathname }));

  addEventListener("error", (event) => {
    const el = event.target;
    if (el instanceof HTMLScriptElement && el.src.startsWith(location.origin)) report("script-failed", el.src);
  }, true);

  addEventListener("load", () => setTimeout(() => {
    if (!document.getElementById("root")?.hasChildNodes()) report("blank", "");
  }, 5000));
</script>

The origin check skips third-party scripts that ad blockers stop; a CSP that blocks inline scripts needs a nonce or hash here. A post-deploy smoke test in a headless browser catches most of these causes, but not deleted files, which only hurt older tabs.

Where GenClass fits

GenClass's measured visual check page-blank reports a page whose main region shows no text and no media 3 seconds after the page settles and again 2 seconds later. It stays silent while a request is in flight or the tab is hidden, and names the CSS property when text is there but hidden, such as opacity: 0 on main. It is a measurement with fixed thresholds, with no model involved, and it changes nothing. On GenClass's bench in Chromium it found 18 of 18 blank pages planted in demo, template and compatibility apps, with 0 false reports in 128 page views of the unmodified apps. The checks' author planted the faults, and the false-report rate on other sites is not known.

In your app the check runs on development hosts by default (visual: true turns it on everywhere, report-only). Imported in your bundle, it cannot report a bundle that never ran. For a live site, start with the free page check, which needs nothing installed: it loads a public page in a fresh browser, reports a blank page as "The main part of the page shows nothing" and lists uncaught errors and failed same-site requests under Reliability. Signed out, you see the score and the three worst findings in full. It cannot see errors that only reach tabs opened before a deploy, and it does not test older browsers.

Questions

Why is my React app blank after I deploy it?

A 404 on the main script means a wrong base path, and a failed lazy-loaded file means the deploy deleted it. Otherwise, start from the first console error.

Why is the page blank with no error in the console?

CSS may hide content that is there, such as opacity: 0 left by a fade-in, or a component may render nothing for a missing value.

Why is my Vite build blank when I open index.html from disk?

Its scripts do not run from a file:// address. Serve the build over HTTP, for example with npx vite preview.

Related: frontend bug monitoring, reproducing production bugs and undefined or NaN on the page.

Talk to sales

Tell us about your team and what you need. A person writes back, usually within a day.