Skip to content

Server push (SSE / WebSocket) for streaming responses and real-time UIs #16

Description

@LoboGuardian

Summary (enhancement)

HTeaLeaf has no server→client push: the ASGI adapter always sends a single http.response.body with more_body=False, and there's no websocket scope handling. Reactivity is request/response + Store re-fetch, never streaming. This blocks an important class of apps — anything that streams data incrementally.

Use case

We want to host a chat UI that streams LLM tokens as they're generated (today done over a WebSocket, token-by-token into the DOM). With HTeaLeaf as-is, every token would need a separate round-trip. This is the single feature keeping us on FastAPI for the real-time parts while we use HTeaLeaf for static SSR views.

What would unlock it (any one is a good start)

  1. Chunked/streaming HTTP responses — let a handler return an async iterator / generator, and have the ASGI adapter emit multiple http.response.body events with more_body=True. Enables SSE (text/event-stream) for one-way server→client streams.
  2. WebSocket scope support in the ASGI adapter (scope["type"] == "websocket"), with a route/handler API for bidirectional messages.
  3. A Store/reconciliation hook so a server-side state change can push a DOM patch to connected clients (vs. the current client-initiated re-fetch).

SSE (option 1) alone would cover most streaming dashboards and token streaming.

Context

Raised while evaluating HTeaLeaf to eventually replace a Vue + FastAPI stack with pure Python. SSR + mounting already work well for static views; server push is the remaining architectural gap for the dynamic ones.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions