r/coolgithubprojects • • 7d ago

Lithent: a ~4.8KB UI library where component state is plain closure variables, no hooks (JSX or no-build templates, SSR, Custom Elements)

https://github.com/superlucky84/lithent
1 Upvotes

1 comment sorted by

1

u/Plenty_Ordinary_5744 7d ago

Author here. Lithent is a small virtual-DOM library I've been building for UIs where a full framework runtime is too much, especially widgets embedded in pages you don't own.

The idea: component state is just variables in a closure. You call renew() when you want a redraw, or use the optional reactive helpers (lstate, store).

const Counter = mount(renew => {
  let count = 0;
  const inc = () => { count += 1; renew(); };
  return () => <button onClick={inc}>{count}</button>;
});

No rules of hooks, no dependency arrays.

Numbers, honestly:

  • Core is ~4.8KB Brotli. That's the same weight class as Preact, so size isn't the selling point.
  • In the official js-framework-benchmark results (Chrome 156), the weighted CPU score is 1.29, next to Lit 1.28, Vue 1.30 and Preact 1.31. React hooks scores 1.56. The entry carries note #1261 (manual caching) because the rows use cacheUpdate.
  • I built the same feedback widget with Lithent, React, Preact and Lit and measured size and load time: https://superlucky84.github.io/lithent/widget-compare/

Extras ship as subpaths of the one package:

  • lithent/element: register a component as a standard Custom Element (<1KB on top)
  • lithent/ssr: server rendering + hydration
  • lithent/ftags: no-build templates
  • lithent/test: render / act / cleanup for Vitest + Testing Library

Try it: npx create-lithent@latest (SPA, SSR or widget template). Docs: https://superlucky84.github.io/lithent/

It's a good fit for small apps and embeddable widgets. If you rely on the React ecosystem, it isn't. Feedback on the API is very welcome.