r/javascript • • Oct 23 '26

I spent three years building Nanoviews, a tiny UI library on signals. It just hit 1.0

https://dangreen.blog/post/why-you-should-try-nanoviews/

Author here. Nanoviews builds real DOM once, and signals update it in place. No JSX, no virtual DOM. It's around 4 kB gzipped and even runs without a build step. The same weather app weighs 10 kB with Nanoviews versus 66 kB with React. In js-framework-benchmark it comes right behind Solid and Svelte. There's a StackBlitz demo in the post.

74 Upvotes

42 comments sorted by

27

u/speechlessnpc Oct 23 '26

Love seeing view libraries find new approaches to the problem of rendering a reactive UI, but not having html templates is a big no no for me

9

u/dangreen58 Oct 23 '26

Thanks! I agree, templates are easier to read and take in at a glance. Unfortunately they come at a cost: either a bigger runtime to parse them, or a build step to compile them.

5

u/MediocreAnalyst2121 Oct 23 '26

Probably not what this library is aiming for but pretty much everything in the web uses some kind of a build step, be it Typescript, Sass, minification, etc.

1

u/dangreen58 Oct 23 '26

You're right, that's not what it's aiming for. No compile step was never the goal, it's more of a side effect of building views from plain function calls. The main points are the size, performance close to Solid and Svelte, and the Nano Kit ecosystem around it. And even without a compiler, apps come out smaller: the same weather app is 10.4 kB gzipped with Nanoviews, 13.6 kB with Solid and 23.1 kB with Svelte.

5

u/speechlessnpc Oct 23 '26

Definitely, but how much bigger? Maybe 4 more kilobytes is fine for a library like this.

2

u/GodOfSunHimself Oct 24 '26

Exactly the opposite for me. Quasi html templates (angular, vue, svelte) are an immediate showstopper.

5

u/optikalefx Oct 23 '26

Reminds me of ExtJS

2

u/dangreen58 Oct 23 '26

😀

1

u/Suspicious-Disk6077 Oct 24 '26

That’s more like 😩 imo lol

3

u/gaddafiduck_ Oct 23 '26

That’s brutal

3

u/Jakeii Oct 24 '26

This looks like the compiled output of svelte

3

u/dangreen58 Oct 24 '26

Only conceptually: like Svelte, it builds real DOM and updates it with fine-grained reactivity, no virtual DOM. If anything, Svelte's output is closer to Solid's: both compile markup into an HTML string, clone it and walk the DOM to wire up updates. Here's the compiled App from the Vite demo (Svelte 5.57, unminified):

var root = from_html(`...`);
function App($$anchor) {
  var main = root();
  var div = child(main);
  var a = child(div);
  var img = only_child(a);
  var img_1 = only_child(sibling(a, 2));
  reset(div);
  var div_1 = sibling(div, 4);
  Counter(child(div_1), {});
  reset(div_1);
  next(2);
  reset(main);
  template_effect(() => {
    set_attribute(img, "src", vite_default);
    set_attribute(img_1, "src", typescript_default);
  });
  append($$anchor, main);
}

Nanoviews has no such step: the code you write is the code that runs, one call per element.

2

u/_Alpha-Ceph_ Oct 23 '26

Did you get inspired by https://vanjs.org/ and how does Nanoviews set itself apart?

4

u/dangreen58 Oct 23 '26

Not really, I found VanJS when I was already working on Nanoviews. We share the idea of plain function calls instead of templates, but there are some differences:

- Nanoviews runs on a fork of alien-signals, one of the fastest signals libraries out there.
- It comes with a ready ecosystem: Nano Kit gives you stores, data fetching, a router, i18n and dependency injection that bind into views directly, so you can build real production apps with it.
- It's faster. I don't have fresh local numbers for VanJS, but even the old Nanoviews alpha in the published js-framework-benchmark results beats it: 1.36 vs 1.52 weighted geometric mean (React is at 1.59).

VanJS is smaller, about 1 kB, and the extra ~3 kB in Nanoviews pay for all of this.

2

u/FerLuisxd Oct 27 '26

Is this better than alpinejs?

1

u/horizon_games 28d ago

No, it's just different. Alpine.js is battle tested and well used, especially for more server-side-rendered projects.

The OP seems to think tacking on basic routing somehow makes it better than Alpine.

1

u/horizon_games Oct 26 '26

Hmm interesting, but personally if I was going to use a non-JSX custom sorta-HTML JS-ified lang I'd just use Mithril.js. If I wanted reactivity with normal HTML I'd use Alpine.js. And I love build-less libs.

Looks at least like your tags like p() would tag all existing and future attributes and just pass them through? That'd be a benefit.

2

u/dangreen58 Oct 26 '26

Mithril and Alpine are great for smaller things, but I find full apps painful to build with them. Nanoviews comes with Nano Kit around it: modern signals-based reactivity, stores, data fetching, a router, i18n and dependency injection. It's also faster than both: in the latest js-framework-benchmark results, Nanoviews 1.0 scores 1.17 vs 1.58 for Mithril and 2.98 for Alpine: https://krausest.github.io/js-framework-benchmark/2026/chrome156.html

And yes, you got it right: any attribute you pass, existing or future, goes straight to setAttribute. Only a few are special, like events, style, class lists and the value of form controls.

2

u/ReverendCatch 29d ago

It warms my heart to see people mention Mithril

1

u/horizon_games 28d ago

Yeah I've been a fan of it and built a significant project years ago with just Mithril. In a lot of ways they were ahead of their time.

6

u/TorbenKoehn Oct 23 '26

Hmmm tries too much to be an own syntax inside JS imho

3

u/eracodes Oct 23 '26

love tiny libraries, but the Todos example with the deeply-nested parentheses does not spark joy for me. maybe if there was a constructor layer that could take in an object with meaningfully-named keys. i just think chaining function calls like this gets really opaque really quickly

1

u/ortegaj50 2d ago

Breaking the tree into named view functions may help readability, though the call syntax remains a taste tradeoff.

2

u/barake Oct 24 '26

This is a fun library, the API screams for a F# shim. Appreciate you engaging in the thread! I wish more folks would actually answer questions about their posts and explain their thoughts.

1

u/Spare_Message_3607 Oct 23 '26

Looks like a good compliment for Astro, imo. I was never a fan of Alpine syntax.

1

u/sod0 Oct 23 '26

I like it. I think I accidentally build something similar (without signals) when I told my agent to use compossible functions but not framework. Cool idea for sure. Not sure I'm gonna ever use it though.

1

u/haywire Oct 23 '26

Why does anyone care about 56kB?

1

u/gianluca_caruso-6 14d ago

For a small app, 56 kB can be a large share of its JS; for a big app, it may be a minor tradeoff.

1

u/tanderson_971 6d ago

Extra JS can add download and startup parse work; network and device constraints matter beyond its share of the app.

1

u/_poor 29d ago

Curious what this syntax would look like in Civet.

-11

u/darcygravan Oct 23 '26

what the hell this is shitty.
at least u should give a html based dsl to author template its awful can u even imaging writing templates like that?

no disrespect but i don't think anybody would use that instead of other frameworks what moat does it have?
writing this and creating dynamic dom nodes via vanilla js is the same damn thing.

and even if u give a dsl its still same concept same reactivity carp. if u really wanna make something try some new approach something innovative new out of the box not just yet another clone of react/solid/vue....

3

u/dangreen58 Oct 23 '26

I get it, templates feel more familiar on the web. But look at mobile: SwiftUI, Jetpack Compose and Flutter all describe UI with plain function calls, no HTML-like templates, and a lot of developers love writing UI that way. Nanoviews brings the same idea to the web, with real DOM and signals under the hood.

2

u/m0rpheus23 Oct 23 '26

Thats is because those languages are built from ground up to work that way. Templating on the web is just built "different". React used to have something similar before pre-JSX, it was quite messy when working with nested ui elements.

I applaud you for your work. I am hopeful you will consider some form of templating in the future

10

u/Mallanaga Oct 23 '26

You can’t really use “no disrespect” and “this is shitty” in the same message.

0

u/[deleted] Oct 23 '26

[deleted] — view deleted comment

1

u/dangreen58 Oct 23 '26

Fair point, most real projects have a bundler anyway. What I meant is that Nanoviews doesn't need its own compile step on top of it: no JSX transform, no template compiler, so your build stays plain TypeScript.

As for JSX, I thought about it. But with JSX, conditions and lists would have to become components, like <Show> and <For> in Solid, and I find that API awkward. I know the syntax will turn some people off, that's the price of the idea :)

1

u/svish Oct 23 '26

Why would conditions need to become components? In React, the original JSX I believe, you just use regular JS for that.

2

u/dangreen58 Oct 23 '26

In React it works because the component re-runs on every state change, so a ternary or .map() is evaluated again each time. Nanoviews, like Solid, has no re-renders: the component runs once, so a plain ternary would never update. Conditions and lists need reactive wrappers instead: if_ and for_ in Nanoviews, or <Show> and <For> if it were JSX.

0

u/LeRages Oct 23 '26

Why is a compile/bundle step something to avoid? It’s 2026… that’s just modern web dev.

0

u/dangreen58 Oct 23 '26

It isn't something to avoid, and Nanoviews works fine with your bundler. No compile step was never the goal, it's a side effect of building views from plain function calls: there's just no extra JSX or template transform in your build. The point of the library is the size, performance close to Solid and Svelte, and the Nano Kit ecosystem.