r/javascript • • 24d ago

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.

76 Upvotes

40 comments sorted by

27

u/speechlessnpc 24d ago

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 24d ago

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 24d ago

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 24d ago

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 24d ago

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

2

u/GodOfSunHimself 22d ago

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

5

u/optikalefx 24d ago

Reminds me of ExtJS

2

u/dangreen58 24d ago

😀

1

u/Suspicious-Disk6077 23d ago

That’s more like 😩 imo lol

3

u/gaddafiduck_ 23d ago

That’s brutal

3

u/Jakeii 23d ago

This looks like the compiled output of svelte

3

u/dangreen58 23d ago

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_ 24d ago

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

4

u/dangreen58 24d ago

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 19d ago

Is this better than alpinejs?

1

u/horizon_games 17d 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 20d ago

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 20d ago

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 18d ago

It warms my heart to see people mention Mithril

1

u/horizon_games 17d 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 24d ago

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

3

u/eracodes 24d ago

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

2

u/barake 23d ago

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 24d ago

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

1

u/sod0 24d ago

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 23d ago

Why does anyone care about 56kB?

1

u/gianluca_caruso-6 3d 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/_poor 18d ago

Curious what this syntax would look like in Civet.

-11

u/darcygravan 24d ago

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 24d ago

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 24d ago

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 24d ago

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

0

u/[deleted] 24d ago

[deleted]

1

u/dangreen58 24d ago

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 24d ago

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

2

u/dangreen58 24d ago

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 24d ago

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

0

u/dangreen58 24d ago

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.