variable / @typed/ui/HttpRouter

streamingSsrForHttp

Registers streaming, GET-only HTML routes for a matcher.

Path captures take precedence over same-named query parameters. HTML chunks are emitted as they are rendered via renderToHtml and HttpServerResponse.stream.

Learn this UI primitive →

Package version
1.0.0-beta.13
Category
Streaming server rendering
Since
1.0.0

Import

import { streamingSsrForHttp } from "@typed/ui/HttpRouter";

Signatures

export declare const streamingSsrForHttp: {
    <E, R>(input: Matcher<RenderEvent, E, R>): (router: HttpRouter) => SsrForHttpEffect<E, R>;
    <E, R>(router: HttpRouter, input: Matcher<RenderEvent, E, R>): SsrForHttpEffect<E, R>;
};

Why

Streaming lets the server send ordered renderer-owned HTML chunks before the whole page completes while preserving the same Typed matcher and Effect HTTP model.

Ownership and lifetime

Registration adds GET routes to the supplied router. Each request owns its navigation/router services and stream Scope. Client cancellation interrupts rendering and runs finalizers. The stream carries typed renderer failures; producing HTML alone does not attach client hydration behavior.

Examples

import { streamingSsrForHttp } from "@typed/ui/HttpRouter"
import { Effect } from "effect"
import * as HttpRouter from "effect/unstable/http/HttpRouter"
import { Parse, match } from "@typed/router"
import { html } from "@typed/template"

const pages = match(Parse("/"), html`<h1>Streamed home</h1>`)
const routes = Effect.gen(function* () {
  const router = yield* HttpRouter.make
  yield* streamingSsrForHttp(router, pages)
  return router
})

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source