oneui for Go
A free, open-source UI component library for Go, MIT or Apache-2.0. A component is an HTML template, optional scoped CSS and a Go struct; go generate compiles it into plain Go that updates only the nodes bound to state that changed.
Render it to HTML, run it in the browser with WebAssembly, or test it without a browser. No dependencies: its go.mod requires nothing.
Quick start
The README’s quick start, run with Go 1.26.8 against v1.0.1 from the module proxy. go generate writes SetCount and the code that rewrites only the button’s text when Count changes.
<button on:click="Increment">Clicked {Count} times</button>
package main //go:generate go run recursiveai.org/go/oneui/cmd/oneui generate import ( "os" "recursiveai.org/go/oneui" ) type Hello struct { oneui.Base Count int `oneui:"state"` } func (h *Hello) Increment() { h.SetCount(h.Count + 1) } func main() { h := &Hello{} h.Increment() oneui.RenderHTML(os.Stdout, h) }
go mod init example.com/hello go get recursiveai.org/go/oneui@v1.0.1 go generate ./... go run .
<button>Clicked 1 times</button>
Fixed in 1.0.1
- Submit buttons
In the reference document, “a click on a submit button […] now submits its form owner: the form’s
submitevent is raised, bubbles, and can be cancelled, as in the HTML Standard.” Arequiredcontrol without a value blocks submission unless the submitter hasformnovalidateor the form hasnovalidate. - Enter key
“Enter in a text-like field submits implicitly.” “Enter or Space on a focused submit button, and a click on a label for one, submit too.”
- Browser
In the browser backend, “forms submit natively, so handlers see the browser’s own
submitevent once”, and “a form withon:submitno longer reloads the page.” - Tests
Added
oneuitest.Page.Press(selector, key).
Speed
The repository’s benchmark: a list of 1,000 rows written three ways, each checked to produce the same markup first. Median time per operation of six counts on an AMD Ryzen 9 7950X3D with Go 1.26.8 on Linux.
What each row measures| Row | oneui | templ | go-app |
|---|---|---|---|
| Render to HTML | 28.3 µs | 537 µs | 1.11 ms |
| Mount to change set, cold | 736 µs | not a job templ does | tree build 687 µs |
| Update one row, live (change set) | 13.9 µs | no live update | wasm only |
| Update one row, server-side re-render | 29.1 µs | 471 µs | 1.08 ms (render function only) |
| Update every row, server-side re-render | 29.5 µs | 500 µs | 1.18 ms |
Mounting a cold context to a change set takes 736 µs against go-app’s element-tree build at 687 µs, 7% slower, with 38% fewer allocations; warm (a long-lived context) it is 575 µs, ahead.
What it does
- Version
oneui v1.0.1. Go 1.24 or newer.
- Templates
oneui generate, run from//go:generate, compiles each template into plain Go. Templates have text and attribute bindings, events, two-waybind:value,class:toggles,if/elseand keyedeach, with optional scoped CSS. A name the struct doesn’t have is reported asfile:line:col. - State
A field tagged
oneui:"state"gets a setter, and changing it rewrites only the nodes bound to it. Nothing is diffed and nothing is reflected. - Change sets
Components write every mutation as a backend-neutral change-set stream, in JSON or a compact binary form. The decoders treat input as untrusted and bound its sizes.
- Backends
RenderHTMLwrites the markup for first paint or server-side rendering (no hydration). Packagebrowserruns components in a web page throughGOOS=js GOARCH=wasmas custom elements. Any other sink, such as a native document, applies the same stream. - Tests
Package
oneuitestmounts a component in the reference DOM, with selector and accessibility queries and a manual clock:Mount,Click,Type,Press,Text, no browser. - UI tree
Package
uiis an engine-free retained UI tree with CSS-model styles, flexbox layout, input and focus, tweens and a display list for a host to paint.ui/kitadds buttons, toggles, sliders, dropdowns, tabs, dialogs, lists, tables, scroll views and text inputs, with a light and a dark theme. - Hot reload
In a program built with the
oneui_reloadtag, an edited template that uses only expressions, handlers and components the build already has replaces the running one in place: the component keeps its state, typed text, focus and scroll position. Anything else asks for a rebuild and leaves the component as it was. - Dependencies
None. The module’s
go.modrequires nothing. - License
MIT or Apache-2.0, at your choice.