Skip to content

feat: singlefile adapter#333

Merged
lazarv merged 3 commits intomainfrom
feat/adapter-singlefile
Mar 4, 2026
Merged

feat: singlefile adapter#333
lazarv merged 3 commits intomainfrom
feat/adapter-singlefile

Conversation

@lazarv
Copy link
Owner

@lazarv lazarv commented Mar 4, 2026

Adds a new singlefile adapter that bundles a statically exported React application into a single, self-contained HTML file. All CSS and JavaScript modules are inlined — no external resources are fetched at runtime.

Motivation

This adapter is useful for:

  • Offline-capable apps that work from a file:// URL or a single HTTP request
  • Portable demos or prototypes you can share as a single file
  • Embedding in environments where only one HTML file is allowed (e.g. email attachments, embedded webviews)

How it works

  1. Static export — Forces --export of the "/" route to produce index.html
  2. CSS inlining — Replaces <link rel="stylesheet"> tags with inline <style> blocks; CSS references in RSC flight data are converted to data:text/css;base64,... URIs so React's runtime stylesheet creation still works
  3. JS module inlining — All client ES modules are base64-encoded, embedded in a boot <script>, and decoded at runtime into blob URLs wired through a dynamic import map
  4. Import rewriting — Relative imports are resolved to absolute paths, then converted to bare specifiers so they resolve correctly from blob URL modules
  5. Cleanup — Modulepreload hints, dev-only live-reload links, and the static import map are removed

Usage

pnpm react-server build ./src/index.jsx --adapter singlefile

Or via config:

export default {
  adapter: "singlefile",
};

Output: dist/index.html — a single file containing everything.

Limitations

  • Single route only — Only the "/" path is exported
  • No server-side features — Server actions, API routes, and dynamic rendering are not available
  • File size overhead — Base64 encoding adds ~33% to JS module sizes
  • SPA mode recommended — Works best with single-page applications using client components

Note: This adapter is marked as experimental and may change in future releases.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 4, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
react-server-docs 317db01 Mar 04 2026, 09:59 PM

@lazarv lazarv changed the title Feat/adapter singlefile feat: singlefile adapter Mar 4, 2026
@lazarv lazarv merged commit 6749868 into main Mar 4, 2026
100 of 101 checks passed
@lazarv lazarv deleted the feat/adapter-singlefile branch March 4, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant