`jfyne/live` Puts Your Entire Frontend Inside One Go Goroutine
A Phoenix LiveView port for Go that swaps React, a build step, and a mutex for `html/template` and a single channel-driven loop.
- `jfyne/live` keeps every user's UI state on the server and ships the browser only the HTML patches it needs.
- The engine serializes all socket access through one goroutine, so the registry needs no mutex at all.
- Event handlers return the new state instead of mutating it, carrying the Elm pattern into idiomatic Go.
- A draft v2 would shift the project from full-page LiveViews toward island-scoped interactivity with WebSocket and SSE negotiation.
One Goroutine Owns Every Session
Open `engine.go` and look for a `sync.Mutex`. There is not one guarding the socket registry. Instead, a single goroutine owns a plain `map[SocketID]*Socket`, and every other part of the program reaches that map by sending an operation struct down a channel and blocking for the reply.
The loop is small enough to read in one sitting.
func (e *Engine) operate(ctx context.Context) {
socketMap := map[SocketID]*Socket{}
for {
select {
case op := <-e.addSocketC:
socketMap[op.Socket.ID()] = op.Socket
op.resp <- struct{}{}
case op := <-e.getSocketC:
...
case op := <-e.deleteSocketC:
delete(socketMap, op.ID)
op.resp <- struct{}{}
case op := <-e.iterateSocketsC:
op.resp <- slices.Collect(maps.Values(socketMap))
case <-ctx.Done():
return
}
}
}
The public methods `AddSocket`, `GetSocket`, and `DeleteSocket` never touch the map. They build an op, drop it on the matching channel, and wait on a per-request `resp` channel for the result. This is the actor model, hand-rolled with Go channels: state lives behind one owner, and messages are the only way in.
The trade is explicit. The registry is trivially race-free and easy to reason about because there is exactly one writer. Every lookup is serialized through that one goroutine, and each `GetSocket` costs two channel hops. For a chat app or a dashboard with thousands of sockets, that is almost certainly fine. For a hot loop hammering the lookup path, it would become the bottleneck. The package ships `socket_race_test.go`, which suggests the authors stress-tested this deliberately rather than stumbling into it.
The Browser Is a Dumb Terminal
If the server owns the state, the browser does not need to. That is the whole philosophy, and `jfyne/live` leans into it hard.
A GET handler calls `MountHandler` and renders HTML. The browser opens a WebSocket and the server re-mounts the socket. A click fires `live-click="temp-up"`, which ships a bare event name over the wire. The server runs the registered handler, re-renders, and sends back a patch. The client applies it to the live DOM. The browser never holds application state; it just paints what the server tells it to.
Real-time user experiences with server-rendered HTML in Go. Inspired by and borrowing from Phoenix LiveViews.
Because it is compatible with `net/http`, it drops under existing middleware without a rewrite. The bindings cover the usual ground: `live-click`, `live-keydown` and `live-keyup`, `live-focus` and `live-blur`, plus `live-change` and `live-submit` for forms. There is no bundler, no `package.json` in your app, and no client-side router.
Diffing HTML Trees, Not DOMs
The obvious way to send an update is to re-render the page and ship the whole thing. That would be correct and wasteful. `jfyne/live` does something smarter: after re-rendering through `html/template`, it parses the output with `golang.org/x/net/html` and diffs the node trees against the previous render.
Because it compares structure rather than raw strings, a reordered attribute or a whitespace change does not register as a difference. Only nodes that actually changed produce patches, and only patches go over the socket. The `web/src/` client then walks those patches and mutates the live DOM in place.
The cost lands where you would expect. Every interaction is a round trip. A keystroke bound with `live-keydown` travels to the server, runs a handler, re-renders, diffs, and comes back. On a fast connection that is imperceptible. On a slow one, or for a control that needs instant local feedback, it is the price of keeping the browser dumb.
Return the New State
The developer-facing contract is a set of plain function types, not an interface hierarchy. The one that shapes everything else is the event handler.
type EventHandler func(context.Context, *Socket, Params) (any, error)
Read the return type carefully. It is `(any, error)`. Whatever the handler returns becomes the new model. The framework assigns it to the socket and re-renders. There is no `setState`, no observable, no store. You compute the next state, hand it back, and the loop does the rest.
This is the Elm architecture, and it is the same shape Phoenix uses. State is a value that flows in and a value that flows out, which makes handlers easy to test and easy to reason about. The rest of the surface stays small for the same reason. `NewHandler` ships a default `RenderHandler` that returns `ErrNoRenderer`, so forgetting to wire up a renderer fails loudly at the first mount rather than silently serving blank pages. Bad `HandlerConfig`, by contrast, only logs a warning and continues, which keeps construction infallible but means a misconfigured handler can start in a degraded state.
Live is intended as a replacement for React, Vue, Angular etc. You can write an interactive web app just using Go and its templates.
Where It Sits
The LiveView idea has now been ported into most major web ecosystems. What separates the implementations is mostly where state lives and how much of a build pipeline the application code drags in.
| Project | Language | Transport | Where state lives | Build step for app code |
|---|---|---|---|---|
| jfyne/live | Go | WebSocket | Server | None (templates) |
| Phoenix LiveView | Elixir | WebSocket | Server | None |
| Livewire | PHP / Laravel | HTTP / Ajax | Server | None |
| LiveViewJS | TypeScript | WebSocket | Server | TypeScript toolchain |
| axum-live-view | Rust / Axum | WebSocket | Server | None |
| React / Vue / Angular | JavaScript / TypeScript | n/a | Client | Bundler required |
The honest comparison point is Phoenix, the project it explicitly borrows from. One community commenter relayed through a Hacker News roundup put it plainly: the Go port has "allowed me to avoid mountains of JS," while judging its API and efficiency less favorably than Phoenix. That is a single anecdote, not a benchmark, but it lines up with the design. `jfyne/live` trades Phoenix's polished abstractions for a smaller surface that lives inside Go's standard HTTP ecosystem.
The Rewrite Nobody Shipped
There is an open draft pull request, number 116, that proposes a substantial v2. It would replace the `Handler`, `Socket`, and `Component` abstractions with islands, sessions, and a transport interface, plus a new TypeScript client and negotiation between WebSocket and SSE.
To be clear: this is an unmerged draft proposal, not released behavior. Nothing in the sections above depends on it. But the direction is telling. Moving from full-page LiveViews to island-scoped interactivity would make the project less directly comparable to Phoenix's full-page model, and more like a set of independently hydrated regions on an otherwise static page.
There is a second signal worth reading. The repo carries a `docs/knowledge/` directory with files named `architecture.md`, `conventions.md`, `workflow.md`, and `guidelines.md`. Alongside dated working notes in `docs/plans/` and `docs/research/`, that structure reads like documentation written to be consumed by AI coding agents as much as by humans. It hints at how the project is now maintained: a small core, a clear contract, and a paper trail designed for tools to pick up.
So the story closes on a genuine open question. The interesting part of `jfyne/live` is not that it ports LiveView to Go. It is that it commits fully to the server owning everything: the UI state, the rendering, the diffing, and even the concurrency model. One goroutine owns every session. Whether the next version keeps that commitment, or scatters it into islands, is still on the table.





