Single-page React apps have a well-known SEO problem. A crawler that doesn’t execute JavaScript hits your site and sees this:
<div id="root"></div>
Nothing else. No title, no description, no content. Everything a search engine or a link-unfurling bot cares about only exists after React mounts, runs its components, and renders into that div. Some crawlers do execute JS now, but not reliably, not consistently, and not for every route on your site with the same timing guarantees. If SEO matters to you, you can’t leave that to chance.
I ran into this directly while working on my portfolio site, guicoder.com. Here’s the two-part fix: react-helmet-async to manage per-route metadata, and a custom Puppeteer prerendering script to bake that metadata into static HTML at build time.
Part one: per-route metadata with react-helmet-async
By default, a React SPA has one <title> and one set of meta tags defined once in public/index.html. Every route shares them. That’s a problem if you want each page to describe itself accurately: your resume page and your samples page shouldn’t have identical titles and descriptions.
react-helmet-async solves this by letting each route declare its own head content as part of its component tree. A page component might render something like:
<Seo
title="Samples | Guicoder"
description="A collection of accessible React components and applications."
canonical="https://guicoder.com/samples"
/>
Internally, that component uses react-helmet-async‘s <Helmet> to inject the title, description, canonical link, and Open Graph tags into <head> at runtime. Navigate to a different route, and the tags update to match.
This is a real improvement, but it only exists after JavaScript runs. It’s a runtime fix. If a crawler doesn’t execute your JS, or gives up before helmet’s effect fires, none of it matters.
Part two: capturing the rendered output with Puppeteer
This is where prerendering comes in. The idea: instead of hoping a crawler will run your JS correctly, run it yourself, once, at build time, and save the result as static HTML.
The rough shape of the process:
- Build the app normally.
- Spin up a local static server serving the build output.
- Launch a headless browser (Puppeteer) and visit each route.
- Wait for React to mount and helmet to inject its tags.
- Grab the fully-rendered HTML from the page.
- Write that HTML to disk at the matching route path.
The result is a set of static files like build/samples/index.html, build/resume/index.html, each containing the correct title, description, canonical URL, and OG tags for that specific route, already present in the markup a crawler receives on first load. Once the page’s own JS kicks in, React hydrates over that markup and the app behaves like a normal SPA from there.
The part that’s easy to get wrong: timing
The tricky detail is step 4. React mounting and helmet committing its tags don’t happen instantly, and they don’t happen in lockstep with typical “page ready” signals like Puppeteer’s networkidle0. If you snapshot too early, you capture the DOM before helmet has written anything route-specific, and every one of your prerendered pages ends up with the same default metadata baked in. That defeats the entire point.
The fix is to wait for a specific, verifiable signal rather than a generic timeout. Checking for any non-empty meta description tag isn’t reliable if a static default value already exists in your HTML template; that check can pass before the route-specific value ever loads. A more precise approach is to wait for the canonical link tag to match the exact URL expected for that route:
await page.waitForFunction(
(expectedPath) => {
const canonical = document.querySelector('link[rel="canonical"]');
return !!canonical && canonical.href.endsWith(expectedPath);
},
{timeout: 10000},
route,
);
This only proceeds once the canonical tag actually reflects the current route, which means helmet has committed its changes and the snapshot will be accurate. Only after that check passes does the script call page.content() and write the file.
Why not just use an existing tool
Tools like react-snap package this whole workflow, using Puppeteer under the hood with generic heuristics for detecting when a page is ready. They work fine for simple cases, but the heuristics aren’t aware of your app’s specific rendering pipeline or of exactly when helmet commits its changes. That mismatch is precisely the class of bug described above, and it’s easier to introduce than to catch. Writing the prerender script by hand costs more upfront, but it means the “is this page actually ready” check is built around something you control and can verify directly, rather than a guess made by a generic tool.
The result
Two pieces working together solve the problem neither solves alone:
- react-helmet-async gives each route control over its own metadata at runtime.
- Puppeteer prerendering captures that metadata into static HTML at build time, so it’s present before any JavaScript runs.
A crawler hitting any route on the site now gets a complete, accurate <head> on the very first response. No JS execution required, no waiting, no guessing.