lithe
A web UI library for Kotlin: single-file components mixing Kotlin and HTML, pre-rendered to HTML and hydrated on a small fine-grained runtime.
Lithe
A web UI library for Kotlin. A component is a .lithe file that mixes Kotlin, HTML and scoped CSS, in the spirit of single-file components. It compiles to plain Kotlin on a small reactive runtime: the page is rendered to HTML at build time, then hydrated in the browser by Kotlin/JS.
Lithe is experimental. Nothing is published to a package repository, so an app is a module of this repository.
What it does
- HTML first. Every page is complete before any JavaScript runs. A page where nothing can change ships none, and a page where only some components can hydrates those alone, as islands.
- Fine-grained updates. A component runs once, and each dynamic part of the page follows the state it reads. There is no virtual DOM.
- Plain Kotlin. Props, state and handlers are Kotlin, with the typed DOM of
kotlin-browser, and a client only carries what its components use. - A template language.
@if,@forwith keys,@when,@await,@key, local@funfragments, two-way bindings of inputs, selects, radio and checkbox groups and<details>,<head>elements and scoped styles that take Kotlin values. - Routing.
var path by window.route()follows the URL,matchRoute("/blog/:slug", path)picks the content, and links move without reloading through the Navigation API where the browser has it. A router package plugs in as a route source. - Compose interop. Components and Compose HTML composables mount each other, and only the sites that use Compose ship it. In a Kobweb site, a
.lithefile underpagesis a page, with the route of its file name. - Tooling. A dev server that rebuilds on save, and reloads an edit of the markup texts without a Kotlin compile, plus a language server with a VS Code extension and a setup for IntelliJ IDEA.
Browser target: Baseline early 2025.
Quick start
The Kotlin toolchain wrappers are committed and provide the JDK, so a shell is all it takes. On Windows, use .\kotlin.bat instead of ./kotlin.
examples/tasks is a complete app, and examples/features/ has one small app per feature. ./kotlin test runs every test, the end to end ones in a headless Chrome when one is installed.
How it compares
The todo example against the same page written with Svelte, both pre-rendered and hydrated:
todo page |
Lithe | Svelte |
|---|---|---|
| JavaScript, Brotli | 16.9 KB | 22.0 KB |
| Hydration, desktop CPU | 8.6 ms | 9.2 ms |
| Hydration, CPU slowed 4x | 48.7 ms | 47.5 ms |
On a table, Svelte is ahead for creating 1,000 rows (6.4 ms against 9.8 ms) and hydrating them (9.8 ms against 16.3 ms), and Lithe for selecting one row among 10,000 (1.9 ms against 4.1 ms). Benchmarks has the method, the ranges and every other figure.
Documentation
| Page | Content |
|---|---|
| Syntax | How to write a component. |
| Architecture | How a .lithe file becomes HTML and JavaScript. |
| Runtime | The node API, server rendering, hydration, islands and routing. |
| Compiler | How components are checked and compiled. |
| Errors | Every error and warning, with its cause. |
| Dev server | Serving an app while editing it. |
| Editors | The language server, VS Code and IntelliJ IDEA. |
| Development | Site builds, tests and the build cache. |
| Project layout | The modules of this repository. |
| Benchmarks | Sizes and times. |
License
This project is licensed under the Apache License 2.0, see the LICENSE file for details.
Pierre Roy