Linora

0404. In-browser demo: a separate static entry on local in-memory pages

Status: Accepted (2026-11-30). Builds on 0402 (React shell, framework-free controllers) and the website decision in 0026.

Context

The launch needs a “try it in your browser” page: one click, no install, and people feel the speed. The maintainer’s requirements:

The app already had an offline mode: without an API, every route opened the editor on createLocalSession. That mode is not enough for a public demo:

Decision

  1. A separate Vite entry, not a runtime flag. apps/web/demo.html and src/demo/main.tsx are built by vite build --mode demo (npm run build:demo) into apps/web/dist-demo/. The page ships as index.html.
    • The entry never imports the API client, FileController, the router or the account, token and file screens. The bundler drops the sync client’s network code (RemoteSyncClient, RealtimeConnection) because nothing references it.
    • The production build (vite build, index.html) keeps its config and entry, and no code path in the app changed.
  2. Relative base (./). Scripts, styles and the bundled font load from paths relative to the page: the font through new URL(..., import.meta.url), the rest from ./assets/. The same files work at /linora/demo/, on a fork’s Pages site and from any local static server. The build is one chunk (the demo opens straight into the editor, so nothing loads lazily) and has no modulepreload polyfill.
  3. Local session per page. DemoFile (src/demo/demoFile.ts) stands in for FileController. It keeps pages in memory, each on its own createLocalSession(createDoc(id)) (the existing DocSession implementation the tests and the bench already use), and swaps them with setSession, keeping a camera per page.
    • It implements the shell’s EditorHost and the new PagesHost interface, so the existing EditorFrame, the panels and PagesPanel render it unchanged. PagesHost is a type-only change in EditorChrome.tsx, and FileController satisfies it.
    • Hidden pages stay open, so their content survives page switches. Closing the tab discards everything.
  4. Demo UI.
    • A slim banner: “Demo: runs entirely in your browser; nothing is saved”, links to the repo and the docs, and two buttons, “Load a 100-page website” and “Load 1M shapes”. Each button opens a new page and runs the perf panel’s generator on it (addSite(100), addStress(1_000_000, 'mixed')). A toast reports the time up to the frame that carries the GPU upload.
    • The perf panel stays where it is in the right panel, visible by default, with the stats, the generators and the benchmarks.
    • The first page, “Welcome”, holds a sample scene of three frames (58 real layers, ASCII text measured like the text tool, committed as one non-undoable batch). The camera opens on the Welcome frame.
    • Below 760 px wide the side panels are hidden, leaving the canvas, the toolbar and the stats HUD.
  5. "sideEffects": false on @linorahq/shared. The contracts package has no import-time side effects, only declarations. The flag lets the bundler drop shared modules that a build does not use. The demo loses the /v1 route table and request schemas (api.ts) and the MCP tool schemas (mcp.ts).
  6. Checks.
    • apps/web/test/demo-build.test.ts (npm test) builds the demo into a temp folder and asserts:
      • index.html with relative asset URLs only, all present;
      • no /v1, WebSocket, EventSource, XHR, beacon, fetch call, worker, service worker or SharedArrayBuffer in the bundle;
      • no absolute URLs beyond XML namespaces, React’s error page and the banner’s two links;
      • the production React build, and a 200 KB gzip budget for the script.
    • apps/web/test/demo.test.ts tests the scene and the page actions.
    • tools/demo/check.ts is the browser check: headless Chrome against a plain static server under /linora/demo/ (no custom headers). It records every request and socket, and with --perf measures the demo against the full app.
  7. Pages. .github/workflows/pages.yml runs npm ci and npm run build:demo, and copies apps/web/dist-demo into _site/demo/. The workflow’s pinning and permission rules are unchanged; setup-node gains npm caching, as in ci.yml.

Alternatives

Consequences