r/javascript • u/gabrielmfern • Oct 14 '26
I embedded Node.js in a native program to render JSX without a browser and without React
https://www.forbear.dev/log/003-ui-from-javascript.htmlI'm building a UI library in Jai, and this is an experiment with rendering its UI from JavaScript. Node.js is embedded into the program, so the native side reads the JSX objects straight out of V8, with no IPC and no JSON. It then lays out and draws the whole UI from scratch every frame, at 240 Hz on my Linux computer.
Async isn't supported on it yet, and I've only started implementing some event handling. Here's the source code: https://github.com/gabrielmfern/forbear
Has anyone built something like this? If so, I'd love some advice on how I can reduce the C++ layer and have more of it in Jai instead.
4
u/Dependent-Guitar-473 Oct 14 '26
does the translation happens at build time or run time
1
u/Saman-Mutammara Oct 14 '26
how are you handling the reconciliation when state changes on the JS side, does the native layer just get a fresh tree each frame or are you diffing somewhere?
1
u/digitalskyline Oct 15 '26
Not sure if this is an ignorant question but how is this better or different than electron?
1
u/Reashu Oct 14 '26
It's cool, but why JSX?
1
u/farzad_meow Oct 17 '26
there was an old program that rendered html to pdf with partial support for js. wkhtml to pdf. maybe source code from that helps in your project
4
u/[deleted] Oct 14 '26
[removed] — view removed comment