News for hackers. Stuff that matters.
Re:Understanding React Compiler by ttfkam on Friday June 28, 2024 @07:04PM (#40826269)
What's the smallest "Hello ${name}" hooked up to an input field you can make deployable in React?

Svelte's is about 2.1KB last I checked. Can React get below 40KB?

Re:Understanding React Compiler by acemarke on Friday June 28, 2024 @07:26PM (#40826419)
Re:Understanding React Compiler by throwAGIway on Saturday June 29, 2024 @08:57AM (#40830138)
Note that this is the full package, and that it's normal to use a bundler that will treeshake things you don't use away. For example react-dom includes server-side rendering functions that are not necessary on browser side.
Re:Understanding React Compiler by acemarke on Saturday June 29, 2024 @11:25AM (#40831239)
Afraid that's not accurate.

The package size I linked is specifically the `react-dom.production.min.js` bundle that is used on the client side. The `react-dom` package does include _separate_ bundles used for server rendering, but that whole React client bundle will get included in your app, and it does _not_ tree-shake at all.

(To be clear I _like_ React, but it's best to be accurate about what happens here.)

Re:Understanding React Compiler by throwAGIway on Saturday June 29, 2024 @04:53PM (#40833281)
So this package is not the actual react-dom package I get when I npm install react-dom? Thanks for the correction!
Re:Understanding React Compiler by acemarke on Sunday June 30, 2024 @12:03PM (#40837959)
The `react-dom` NPM package includes multiple different JS bundles that are used for different purposes. See that `unpkg` link I pasted in the parent comment.

There's 3 different flavors of `react-dom` for use in the client (dev, prod, profiling), and then several variations of `react-dom` for use _on the server_.

The client bundles don't include any of the server functionality.

_None_ of the bundles are treeshakeable at all, because A) they're shipped as CommonJS modules and not ESM, and B) the way the React library is written and architectured as a whole. All of the reconciler logic is intertwined and unshakeable, so even if React did suddenly switch to shipping ESM modules instead of CJS, it would still end up as the exact same bundle size.

Re:Understanding React Compiler by ttfkam on Saturday June 29, 2024 @10:45AM (#40830981)
So how small can you get for a hello world page with a single "hello $name" component, spending an hour or less on it?
Re:Understanding React Compiler by acemarke on Saturday June 29, 2024 @11:30AM (#40831262)
That bundle size + the size of your component.

Just created a fresh Vite+React app and rendered a "hello world" component, and the resulting output is:

    dist/assets/index-uoOveHrm.js   142.66 kB │ gzip: 45.76 kB
Re:Understanding React Compiler by throwAGIway on Friday June 28, 2024 @09:25PM (#40827157)
Go for Preact if bundle size is your concern.
Re:Understanding React Compiler by ttfkam on Saturday June 29, 2024 @11:19AM (#40831195)
I'd rather go to Svelte for lower bundle size than Preact, better performance than Preact, and clearer code with fewer lines written than Preact.

Sure, I'd lose access to the React ecosystem, but I'd also gain access to the vast ecosystem of vanilla JS libraries without having to write/use a wrapper, so that's a wash. (bind:this is awesome!)

Re:Understanding React Compiler by throwAGIway on Sunday June 30, 2024 @03:48AM (#40835726)
Yep, sure! Personally I don't like the Svelte programming model, and I like Preact signals a lot, and hooks are fine to me. But Svelte is definitely a good way overall.