C · Fast & interactiveIntermediate11 min read

How I Built anjay.dev: React 19, Vite and a Prerendered Multi-Page Site

Cinematic canvas visuals, a perfect crawl and no framework server. The architecture, the real code, and the three bugs that bit me.

TL;DR

  • anjay.dev is a Vite multi-page app: every page has its own HTML entry and React root, deployed as static files on Vercel.
  • A build step renders each page with renderToString and writes the markup into the HTML, so crawlers see full text, links and structured data.
  • The client hydrates inside startTransition, and heavy canvas/WebGL visuals boot only when the main thread is idle.
  • Sitemap, RSS, llms.txt, per-post meta and share images are generated from one post list on every build.

I wanted two things that usually fight each other: a portfolio with heavy, cinematic visuals (particle text, WebGL fields, a circuit-board hero) and a site that search engines and AI assistants can read perfectly. This is how anjay.dev does both with React 19, Vite and build-time prerendering, with real code from the repository and the bugs I hit along the way.

The brief

  • Rich motion: particles that assemble into text, folding WebGL surfaces, a live circuit network behind the hero.
  • Crawlable on the first byte: every heading, paragraph, link and meta tag present in the HTML, before any JavaScript runs.
  • No server to babysit: static files on a CDN, no per-request rendering.
  • Several distinct pages (home, work, contact, insights), each with its own design and SEO head.

A framework like Next.js could do this, but the site needed very little of what a framework adds. Vite plus a small prerender script gave full control in a few hundred lines.

Why a plain SPA was not enough

A default React single-page app ships an almost empty HTML file and builds the page in the browser. Run the crawler below on both versions and compare what it can index.

Interactive · what the crawler sees

Downloaded HTML

<!doctype html>
<html lang="en">
  <head>
    <title>anjay.dev</title>
    <script type="module" src="/assets/index.js"></script>
  </head>
  <body>
    <div id="root"></div>
  </body>
</html>

Indexable

  • title anjay.dev

Almost nothing to index until JavaScript runs. Google may render it later; many other crawlers and AI bots never will.

Google can render JavaScript, but it does so in a separate, later pass, and many other crawlers (including most AI bots) never run it at all. If the words are not in the HTML, you are betting your visibility on someone else’s render queue.

The architecture: one Vite build, many pages

Vite supports multiple HTML entry points out of the box. Each page is its own folder with an index.html and its own React entry, so each one gets its own head, its own bundle and its own design:

vite.config.ts
build: {
  rollupOptions: {
    input: {
      main: resolve(import.meta.dirname, 'index.html'),
      contact: resolve(import.meta.dirname, 'contact/index.html'),
      work: resolve(import.meta.dirname, 'work/index.html'),
      insights: resolve(import.meta.dirname, 'insights/index.html'),
      post: resolve(import.meta.dirname, 'insights/post/index.html'),
    },
  },
},

On Vercel, cleanUrls serves contact/index.html at /contact. Locally, a ten-line Vite plugin does the same rewrite, so dev, preview and production share one URL scheme.

Prerendering at build time

The build runs three steps: the normal client build, an SSR buildA build of your React code for Node instead of the browser, so a script can call renderToString on it. of a tiny server entry, and a script that renders each page to a string and writes it into the HTML:

package.json
"build": "tsc -b && vite build && vite build --ssr src/entry-server.tsx --outDir dist-ssr && node scripts/prerender.mjs"
scripts/prerender.mjs
const { render } = await import('./dist-ssr/entry-server.js')

for (const page of pages) {
  const appHtml = render(page.id) // renderToString(<App />)
  let html = readFileSync(resolve(dist, page.file), 'utf8')
  html = html.replace('<!--app-html-->', appHtml)
  html = html.replace('</title>', `</title>\n    ${fontPreloads}`)
  writeFileSync(resolve(dist, page.file), html)
}

The result is plain static HTML with the full page inside it. This is SSGStatic Site Generation: pages are rendered once at build time and served as files, instead of on every request (SSR)., not per-request server rendering: nothing runs on a server when someone visits.

Hydrating without blocking the page

When the JavaScript arrives, React does not rebuild the page. It hydratesAttaching React's event handlers and state to HTML that is already on screen, instead of re-creating the DOM. the existing markup. Wrapping that in startTransition lets React split the work into chunks, so a tap or scroll during hydration is not stuck behind it:

src/main.tsx
const container = document.getElementById('root')!
// Production HTML is prerendered → hydrate it. In dev the root is empty → client render.
if (container.firstElementChild) startTransition(() => void hydrateRoot(container, app))
else createRoot(container).render(app)

Scrub through the load below to see the order things happen in.

Interactive · scrub the page load

  1. The browser asks for /. Vercel answers from the edge with a static file: no server rendering per request.

  2. The prerendered markup already contains the headline, copy and links. Text can paint before any JavaScript runs.

  3. The two variable fonts are preloaded in the head, so the headline paints in-brand instead of swapping later.

  4. The entry script runs. It finds markup inside #root, so it hydrates instead of rendering from scratch.

  5. hydrateRoot runs inside startTransition, so it can be interrupted: taps and scrolls stay responsive.

  6. The particle engine and canvas fields start in requestIdleCallback, after the page is already usable.

  7. The animated layer fades in over a CSS backdrop that was there from the first paint, so nothing jumps.

The heavy visuals wait for an idle moment. requestIdleCallback is not in Safari, so there is a small fallback:

src/utils/idle.ts
export function onIdle(cb: () => void, timeout = 800): () => void {
  if (typeof window.requestIdleCallback === 'function') {
    const id = window.requestIdleCallback(cb, { timeout })
    return () => window.cancelIdleCallback(id)
  }
  const id = setTimeout(cb, Math.min(timeout, 250))
  return () => clearTimeout(id)
}

See the hydrateRoot docs for the rules: the server and client must render the same markup, which is why every date on this blog is formatted by hand instead of with the visitor’s locale.

Heavy visuals, light main thread

Each canvas renderer on the site follows the same four rules:

  1. Boot on idle, never during the first paint. A CSS backdrop stands in until then.
  2. Pause when unseen: an IntersectionObserver stops the loop off-screen, and visibilitychange stops it in background tabs.
  3. Adapt: if frames run slow, rebuild with fewer particles instead of dropping frames.
  4. Respect reduced motion: draw one composed still frame and stop.
particleEngine.ts (pattern)
this.io = new IntersectionObserver(([entry]) => {
  this.visible = entry.isIntersecting
  if (this.visible) this.start()
  else this.stop()
})
this.io.observe(canvas)
document.addEventListener('visibilitychange', this.onVisibility)
if (opts.reducedMotion) this.renderStatic()

SEO that generates itself

Every insight is a file with a typed meta object. The same prerender script turns that list into everything a search engine or AI assistant needs, so publishing a post is one file and one line:

  • a page per post with its own title, description, canonical and Open Graph tags
  • BlogPosting and BreadcrumbList structured data tied to one Person
  • sitemap.xml with real lastmod dates, an RSS feed and the post list in llms.txt
  • a 1200×630 share image per post, with the title outlined as SVG paths and rendered by sharp
scripts/prerender.mjs (sitemap)
const urls = [
  { loc: `${SITE}/`, lastmod: '2026-11-08' },
  { loc: `${SITE}/insights`, lastmod: newest },
  ...posts.map(({ meta }) => ({ loc: postUrl(meta.slug), lastmod: meta.updated ?? meta.published })),
]

Only indexable pages go in the sitemap. Design experiments live on noindex pages and stay out of it, so Search Console never reports a contradiction.

The small details that make it feel finished

A colour switch with no flash

The navbar has an aurora ↔ ember theme switch. If the saved theme were applied by React, the page would flash the wrong colours first. A few lines in the head apply it before the first paint:

index.html
<script>
  try {
    if (localStorage.getItem('anjay-theme') === 'ember') {
      document.documentElement.classList.add('theme-ember')
    }
  } catch (e) {}
</script>

Fonts that paint in-brand

The prerender script finds the hashed font files in the build output and adds <link rel="preload"> tags, so the display font is ready when the headline paints.

Three bugs that bit me

None of these showed up in type checks. All three were caught by looking at screenshots of the real build, which is now a step I never skip.

The result

Every indexable page (home, work, contact, the insights listing and each post) scores 100 for SEO, accessibility and best practices in Lighthouse, while still running particle and WebGL visuals. The whole setup is a Vite config, one server entry and one build script.

If you want to know what the role behind work like this involves, read What a Next-Gen Web & AI Engineer Actually Does. If you want something similar built, get in touch.

FAQ

Do I need Next.js for good SEO with React?

No. What matters is that the HTML contains your content. Next.js is one way to get there; Vite with a prerender step is another, with less to learn and less to run. The Vite SSR guide covers the building blocks.

Is prerendering the same as server-side rendering?

Same React API, different timing. Prerendering runs once at build time and serves files; SSR runs on every request. Content that changes per visitor needs SSR; a portfolio or blog does not.

Does hydration slow the page down?

It costs some main-thread time, but the page is readable before it starts. Running it inside startTransition and deferring heavy work to idle time keeps the page responsive while it happens.

Quick checkpoint

Checkpoint · 3 questions

  1. Where does the page text live in a prerendered site?

    renderToString writes the markup into the HTML at build time, so it is there on the first byte.

  2. Why wrap hydrateRoot in startTransition?

    Transitions let React yield to user input, so taps and scrolls are not blocked by hydration.

  3. When should a heavy canvas animation start?

    Booting on idle keeps the first paint and first interaction fast; a CSS backdrop covers the wait.

Signal received

Found this useful? Pass it on.

LinkedInX

Written by Anjay Sharma

Next-gen web & AI engineer building intelligent interfaces, fast web applications and AI-powered digital products.