r/react • • 5d ago

Portfolio A React-like JS Framework with Web Components

IMPORTANT DISCLAIMER: This is my own project. Im am using AI, so lets get that out of the way... its the key reason for why YOU SHOULD NOT USE IT. Im not trying to promote "yet another ui framework", this is an investigation to see what is possible. Its unreviewed, unaudited and far from finished. Nobody else should be using this. This framework is intended for myself on my own projects. It is provided open-source for transparency, testing and demo purposes. Feel free to reach out for clarity if you have any questions.

Im was investigating an idea i had about JSX-like syntax for webcomponents after some experience with Lit. I am sharing this here because it might be interesting/educational.

Lit is a nice lightweight UI framework, but i didnt like that it was using class-based components. It can support React with a wrapper, buts React is fundamentally an abstraction away from the DOM.

Vue has a nice approach but i prefer working with the syntax that React uses. I find it more intuitive for debugging and deterministic rendering. I wondered if with webcomponents, i could create a UI framework that didnt need to be transpiled.

My intentions with this framework is to get to a reasonable level of stability, to then replace React on some of my existing projects. I made a start by creating some basic reusable ui components components to be built with the js framework. Aiming for something like Material UI.

I can then compound that slop into some basic UI demos:

The disclaimer above is always worth repeating. Im aiming for a post like this to be like "building in public". If interesting to anyone, i hope its inviting to take a look. It's hard to determine if / when its a good time to share, so best to get it out there sooner for any outstanding issues i may be overlooking.

9 Upvotes

7 comments sorted by

6

u/bliepp 5d ago edited 5d ago

Appreciate the disclaimer. Not only about AI usage, but also about it being a toy project. Also, I really like the idea. Question: Why didn't you use React and just wrote a custom renderer/reconciler that replaces ReactDOM? This would have saved you a few reimplementations, I guess.

1

u/Accurate-Screen8774 5d ago edited 5d ago

I'm a react developer. I appreciate how it works. I also noticed how when compared to web components, it moves away from the dom with synthetic concepts like a virtual dom.

I think there is an elegance to the web component approach with it being part of the browser standard and being available out of the box. that's what I'm trying to share here.

9

u/Honey-Entire 5d ago

Thank you for being one of the few to actually disclose your AI usage. Beyond your own education, is there a reason you didn't reach for a tool like @r2wc? You mentioned liking React's syntax and r2wc creates web components out of your react code

1

u/Dry-Trick-2234 5d ago

r2wc still ships a React runtime so you are paying the bundle cost for something that never hits the virtual dom. My goal was zero runtime and no transpile step, just native custom elements with a tiny reactive layer. The trade off is I have to reimplement props diffing and lifecycle myself which is where the current bugs live.

1

u/Honey-Entire 4d ago

If you don’t want to pay the price of Reacts runtime, why not use Svelte then? It natively supports compiling to we components, includes reactivity by default, and has community options if you really want JSX-like syntax

5

u/OnlyShadowsDieTwice 5d ago

The code is absolute poop, so is the syntax.

1

u/f0rwardz 2h ago

If you are looking for a framework that has a data-binding/reaction layer that supports native Web components, works directly on the DOM and doesn't need a transpiler you could try Componyx.UI too. Although it doesn't use jsx and wasn't build by AI but that's very deliberate.