Skip to content

Effect UI

Neon.Website.EffectUI supports browser-only SPAs, server-side rendering (SSR), static site generation (SSG), and hybrid rendering. It packages the app’s assets and the optional handler HtmlServerVite.plugin generates as a Node 24 Fetch module in a Neon Function ZIP.

Configure deployment credentials and install Alchemy and its matching Effect dependencies. Use Node 24 for this build toolchain, then install the build integration in the app directory:

Terminal window
pnpm add -D https://pkg.alchemy.run/@alchemy.run/frontend-frameworks/9c58f00 @vercel/nft

Effect UI is in public preview and isn’t on npm yet. Install a snapshot build of @effect/ui as its README describes.

A browser-only app needs no plugin. Its Vite config stays what the Effect UI quick start gives you, and the build deploys as static files.

Add HtmlServerVite.plugin and point it at a server entry. With serverOutDir, the build also emits a request handler, which answers every request that matches no file:

vite.config.ts
import { plugin as htmlServer } from "@effect/ui/html/HtmlServerVite";
import { defineConfig } from "vite";
export default defineConfig({
build: { outDir: "dist/client" },
plugins: [
htmlServer({
entry: "/src/entry.server.ts",
serverOutDir: "dist/server",
}),
],
});

The server output must not overlap the client’s, so the client builds to dist/client.

The server entry’s default export is a Layer that adds the app’s routes to HttpRouter. prerender lists the pages the build renders ahead of time. They are served as files, and the server renders everything else:

src/entry.server.ts
/// <reference types="@effect/ui/html/HtmlServerViteDocument" />
import { layerHttp } from "@effect/ui/html/HtmlServerHttp";
import { document } from "virtual:@effect/ui/document";
import { App } from "./App.ts";
import { AppRoute } from "./routes.ts";
export default layerHttp(App, { routes: AppRoute, document });
export const prerender = ["/about", "/404"];

index.html marks where the page goes with <!--app-html-->. The browser entry hydrates the server’s HTML instead of mounting a new app:

src/entry.client.ts
import { Router } from "@effect/ui";
import { BrowserRouter, HtmlHydrate } from "@effect/ui/html";
import { Effect, Layer } from "effect";
import { App } from "./App.ts";
import { AppRoute } from "./routes.ts";
const Main = HtmlHydrate.hydrate(
App,
Router.props(AppRoute),
document.getElementById("app")!,
JSON.parse(document.getElementById("state")!.textContent!),
).pipe(Layer.provide(BrowserRouter.layer({ routes: AppRoute })));
Layer.launch(Main).pipe(Effect.runFork);

Leave serverOutDir out and the build keeps only the prerendered pages. The site deploys as static files, and a prerendered /404 is the page for paths that match nothing:

vite.config.ts
import { plugin as htmlServer } from "@effect/ui/html/HtmlServerVite";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [htmlServer({ entry: "/src/entry.server.ts" })],
});
alchemy.run.ts
import * as Alchemy from "alchemy";
import * as Neon from "@alchemy.run/neon";
import * as Effect from "effect/Effect";
export default Alchemy.Stack(
"NeonEffectUI",
{ providers: Neon.providers(), state: Alchemy.localState() },
Effect.gen(function* () {
const site = yield* Neon.Website.EffectUI("Web", {
rootDir: ".",
});
return { url: site.url };
}),
);

Browser-only builds serve index.html for unmatched GET/HEAD paths so the client router can resolve deep links. vite.outDir overrides the build output directory.

env values with Vite’s VITE_* prefix are embedded into the browser build. Server-rendered apps read private runtime values from process.env. Keep secrets out of VITE_* keys and the server-rendered state because both reach the browser.

Terminal window
pnpm exec alchemy dev
pnpm exec alchemy deploy
pnpm exec alchemy destroy

Run separately, destroying when finished. Dev uses the project’s Vite dev server, where HtmlServerVite renders every page, returns a local URL, and creates no implicit Neon resources. Append .pipe(Alchemy.remote()) to the Website Effect to use live deployment during dev.

Live deploy creates an Ohio Project if no scope is supplied. Pass either project or branch for an existing backend; choose Ohio for combined storage use. Read scope and credentials: account keys and privileged branch tokens must not reach this browser bundle.