News for hackers. Stuff that matters.
Re:VanJS: A 0.9KB JavaScript UI framework by brap on Wednesday December 20, 2023 @01:50PM (#38712170)
I don’t know why they’re selling lack of JSX as a feature. React works without JSX too. It’s just (very convenient) syntactic sugar.
Re:VanJS: A 0.9KB JavaScript UI framework by flying-pig on Wednesday December 20, 2023 @04:28PM (#38713873)
JSX is redundant, at best. VanJS demonstrated ordinary JavaScript syntax is as good as JSX, if not better. How can something feel sugar-ish if it's actually more verbose than ordinary JS code? Plus, you can't really execute JSX code in browser's developer console.
Re:VanJS: A 0.9KB JavaScript UI framework by least on Wednesday December 20, 2023 @05:22PM (#38714430)
> How can something feel sugar-ish if it's actually more verbose than ordinary JS code?

I personally find XML much easier to parse than a lot of nested callbacks and I especially like that content is always inside tags, rather than another argument as part of the library's functions. p("Hello, world") is readable enough, but as soon as you start adding html attributes, it becomes less legible to me:

li(a({href: "https://vanjs.org/"}, "VanJS"))

vs.

<li><a href="https://vanjs.org/">VanJS</a></li>

I'm certain some people probably prefer the former over the latter, but I much prefer how JSX/XML reads. I can immediately tell where the content starts and in formatted code, I think it's a lot easier to see visually where things start and end, because of closing tags, instead of just a parentheses.

Re:VanJS: A 0.9KB JavaScript UI framework by ping-monkey on Wednesday December 20, 2023 @05:41PM (#38714619)
tbh, you don't need JSX to know where things begin and end (if this is something really important for you):

li(a({href: "https://vanjs.org/"}, "VanJS")/*a*/)/*li*/

Re:VanJS: A 0.9KB JavaScript UI framework by mikeryan on Wednesday December 20, 2023 @02:47PM (#38712777)
It is really an odd flex. As soon as you need a transpiler, which many modern JS devs are going to want and need for the benefits they provide (Typescript being huge) then using JSX seems a benefit not a problem to solve.
Re:VanJS: A 0.9KB JavaScript UI framework by simonw on Wednesday December 20, 2023 @03:43PM (#38713393)
Not needing to use a transpiler is genuinely the thing that excites me most about VanJS.

If you're not a daily JavaScript developer, any form of transpiler / build mechanism seems almost guaranteed to break in the gaps between when you are working on a specific project.

The projects I have that are transpiler/build free are SO MUCH more pleasant for me to intermittently hack on!

Re:VanJS: A 0.9KB JavaScript UI framework by earthboundkid on Wednesday December 20, 2023 @04:59PM (#38714208)
Sure, I think that's a very real consideration, but if you're not a daily JS developer, I'm not sure why you'd use a function-call syntax to build up a template either. Something like Alpine.js where you just mark up your server side HTML is a lot easier than putting a bunch of logic into JS to build up a template. Or you could use lit-html or a million other things. This is an idea that's been done a million times but never catches on because it's not better than the alternatives.
Re:VanJS: A 0.9KB JavaScript UI framework by ping-monkey on Wednesday December 20, 2023 @05:47PM (#38714689)
FWIW, for HTML template:

1. How easy is it to support loops? 2. How easy is it to compose (defining small components that can be used in larger components)? 3. How easy is it to make the UI reactive to client-side state changes?

> because it's not better than the alternatives

What is the alternative you're refering?

Re:VanJS: A 0.9KB JavaScript UI framework by nicoburns on Wednesday December 20, 2023 @05:41PM (#38714627)
Have you used esbuild? It’s a transpiler without the faff.
Re:VanJS: A 0.9KB JavaScript UI framework by simonw on Wednesday December 20, 2023 @05:59PM (#38714788)
I've used it via Vite, and it worked fine.

I did write myself EXTENSIVE notes such that when I return to that project in the future I have a fighting change of figuring out how to build it again: https://til.simonwillison.net/github-actions/vite-github-pag...

Re:VanJS: A 0.9KB JavaScript UI framework by c-hendricks on Wednesday December 20, 2023 @11:02PM (#38716861)
You can trim down those notes a lot, like instead of `npm install`, I write a shell script called `script/prepare-env`, instead of various scripts written in a package.json file, I've standardized on `script/start`, `script/build`, and `script/deploy`. Now, no matter the language or package manager used, my workflow is the same.

And you could clean up the GitHub Actions file by just passing the base url to your build script, IE `BASE_URL="/${{ github.event.repository.name }}/" script/build`.

I mean no offense, these notes aren't that extensive, and most of the content is for setting up GitHub Actions / GitHub Pages. npm install / npm run dev / npm run build aren't very esoteric, and can all be documented inside the repo.

I'm actually a little shocked to find out you're a co-creator of Django.

Re:VanJS: A 0.9KB JavaScript UI framework by simonw on Thursday December 21, 2023 @12:22AM (#38717262)
The title of that page is "Serving a JavaScript project built using Vite from GitHub Pages" - that's what those notes are meant to cover, the Vite part is a subset of what I learned in that particular TIL.

Thanks for the BASE_URL environment variable trick - that was very non-obvious to me! I found the documentation for that just now: https://vitejs.dev/guide/env-and-mode

I'm not sure what you mean by "trim down" those notes - if anything I'm always looking for ways to bulk this kind of document up, in order to capture as many of the details of how things work as possible.

I tried the script/x pattern for a bit but I've found that Justfiles fit my brain better - I have a TIL about those here: https://til.simonwillison.net/django/just-with-django

Re:VanJS: A 0.9KB JavaScript UI framework by satvikpendem on Wednesday December 20, 2023 @06:04PM (#38714822)
I use TypeScript exclusively over Javascript so being pure JS is a con not a pro to me.
Re:VanJS: A 0.9KB JavaScript UI framework by pekim on Thursday December 21, 2023 @07:41AM (#38719732)
The library does have Typescript definitions available to use.

https://github.com/vanjs-org/van#typescript-support

Re:VanJS: A 0.9KB JavaScript UI framework by brap on Thursday December 21, 2023 @03:54AM (#38718352)
…you can use React without a transpiler. Without JSX React’s syntax is pretty much identical to this.
Re:VanJS: A 0.9KB JavaScript UI framework by jfengel on Wednesday December 20, 2023 @03:01PM (#38712928)
JSX does seem to fit that niche better than any other alternative I've tried. It pulls off a rather remarkable trick of avoiding the "uncanny valley" that you usually get from starting with a language and contorting it to do something different.

JSX manages to feel just about right: it's plain-old-HTML when you want it to be, and plain-old-Javascript when you need an out.

Still... I wouldn't mind writing in a truly standard language. You're "really" writing the DOM, and HTML and DOM are this godawful bastardization of a user-interface description language. I'd be slightly less grumpy to have a good DOM-writing library, and deal with its ugliness, rather than mix-and-match the domain-specific-language in with my actual coding language.

I'd written myself a good Java version of this type of thing, and I found it kinda pleasant -- especially since it let me do HTML structure checking via the Java type checking. Typescript is -- God help me -- actually a pretty good language, and I'd be OK with actually writing my user interface structure in it, with the help of a good library.

At least then I'm writing in only one language. That saves me time to go out and learn the godawful bodge of CSS to make it look pretty.

Re:VanJS: A 0.9KB JavaScript UI framework by recursive on Wednesday December 20, 2023 @05:10PM (#38714298)
Jsx never achieves plain-old-html in my view. <div /> is legal but <br> isn't.
Re:VanJS: A 0.9KB JavaScript UI framework by nicoburns on Wednesday December 20, 2023 @05:42PM (#38714638)
<br /> is which matches xhtml (if not html5)
Re:VanJS: A 0.9KB JavaScript UI framework by recursive on Wednesday December 20, 2023 @06:20PM (#38714958)
Html 5 has displaced XHTML for decades. And notably, XHTML is not html. <br /> is valid html5, but the trailing slash is meaningless. In JSX, it's required.
Re:VanJS: A 0.9KB JavaScript UI framework by jraph on Wednesday December 20, 2023 @08:12PM (#38715923)
XHTML5 is a thing.
Re:VanJS: A 0.9KB JavaScript UI framework by recursive on Wednesday December 20, 2023 @08:32PM (#38716037)
This is news to me. From what I can find (which is not much), it seems like XHTML5 is a further constraint on HTML5. So legal XHTML5 is legal HTML5.

https://en.wikipedia.org/wiki/HTML5#XHTML_5_(XML-serialized_...

If that's true, that means <div /> is not valid XHTML5 because 1) trailing slashes don't close tags in html and 2) div elements require a closing tag.

And if that's true, then it's still different from JSX. But this XHTML5 thing might be surpassing my comprehension.

Re:VanJS: A 0.9KB JavaScript UI framework by jraph on Thursday December 21, 2023 @04:13AM (#38718471)
> So legal XHTML5 is legal HTML5.

Almost. You would need to make sure to write polyglot markup [1].

> And if that's true, then it's still different from JSX

Absolutely.

[1] https://www.w3.org/TR/html-polyglot/

Re:VanJS: A 0.9KB JavaScript UI framework by ping-monkey on Wednesday December 20, 2023 @05:50PM (#38714713)
If you like JSX, good for you. But tbh it's neither necessary nor the best solution...
Re:VanJS: A 0.9KB JavaScript UI framework by Hammershaft on Thursday December 21, 2023 @04:09AM (#38718450)
Writing the dom cleanly with code with native data structures using clojurescript's hiccup is definitely an improvement.
Re:VanJS: A 0.9KB JavaScript UI framework by briantakita on Wednesday December 20, 2023 @04:48PM (#38714079)
JSX is still a dependency with different variants which can cause issues. For example, SolidJS uses JSX but a different variant of JSX, which is a bit more slimmer (innerHTML instead of dangerouslySetInnerHTML).

I experimented with VanJS integrating into Astro. No plugin was needed & getting the SSR HTML is as simple as calling `.render()`.

I wrote a fork of VanJS called relementjs & took this concept further, using `.toString()` instead of render. Now SSR components can be rendered inside a template string.

` <div>${my_component()}</div> `

Re:VanJS: A 0.9KB JavaScript UI framework by briantakita on Wednesday December 20, 2023 @04:42PM (#38714011)
Build simplicity. It's nice to work with functions all the way down. VanJS could add JSX on top of it though.
Re:VanJS: A 0.9KB JavaScript UI framework by ping-monkey on Wednesday December 20, 2023 @05:51PM (#38714727)
There is some plug-in that adds JSX support though.
Re:VanJS: A 0.9KB JavaScript UI framework by brap on Thursday December 21, 2023 @03:57AM (#38718372)
React is also functions all the way down and the syntax is pretty much identical to this
Re:VanJS: A 0.9KB JavaScript UI framework by mountainriver on Wednesday December 20, 2023 @11:02PM (#38716859)
As a long time backend developer and new front end developer, I gotta say I find JSX to be downright wonderful.

There are some oddities with react but wow jsx makes my code clean and easy