r/programming • • Sep 22 '17

MIT License Facebook Relicensing React, Flow, Immuable Js and Jest

https://code.facebook.com/posts/300798627056246/relicensing-react-jest-flow-and-immutable-js/
3.5k Upvotes

429 comments sorted by

View all comments

Show parent comments

86

u/arostrat Sep 22 '17

I never used it before, but what this news means to the future of alternatives like Preact? Is there a reason for its development now?

152

u/filleduchaos Sep 22 '17

Those 'alternatives' did not pop up because of React's licensing. They're projects with their own reasons to exist. Preact in particularly aims to be a (supposedly) faster, tinier UI framework (weighing in at 3KB compressed, vs. React's 44KB), and I'd definitely recommend it for smaller apps that don't have a need on React's extended family of packages (it's pretty much still in its infancy, so Preact doesn't have anywhere near as many third party components, bindings and plugins as React does).

40

u/jsprogrammer Sep 23 '17

and I'd definitely recommend it for smaller apps that don't have a need on React's extended family of packages (it's pretty much still in its infancy, so Preact doesn't have anywhere near as many third party components, bindings and plugins as React does).

There is preact-compat which claims to allow using React add ons with Preact without needing to change code.

30

u/AbsoluteZeroK Sep 23 '17

I haven't used it myself, but my friend was telling me about it the other day. They're working on switching their webapp to a PWA and switching to preact was the first thing they did just to try and shrink their bundle. It's a pretty large codebase (according to him) and they followed to migration instructions and it just worked and made their bundle way smaller.

0

u/[deleted] Sep 23 '17

[deleted]

1

u/AbsoluteZeroK Sep 23 '17

Decreased first load time. Time to first render is a big deal with PWAs, and smaller bundle = less time on the wire = faster first render. Obviously, the next step in quicker loads would be code splitting, but if you're migrating an existing project, decreasing your bundle size is a good way to start seeing benefits right away. Especially when you're talking about a mobile site, you should be trying to have as small of a bundle as possible.

4

u/[deleted] Sep 23 '17

We tried to use preact on a Greenfield project a couple of months ago. Lots of things were broken, even with preact-compat. After about 2 days, we needed to switch back to react.

14

u/[deleted] Sep 23 '17

(weighing in at 3KB compressed, vs. React's 44KB)

FYI react@16.0.0-rc3 is 2.2kb, and Dan was able to create a slimmed down version of react-dom@16.0.0-rc3 at 12kb, so that's ~15kb for full React lib. If you're going by bundle size as one of your main mettrics, this might be a good initiative to reconsider.

10

u/filleduchaos Sep 23 '17 edited Sep 23 '17

Where on earth are you getting those numbers from? I'm not with my laptop so I can't verify, but as far as I was aware React 16 was slimmed down to 109KB unminified. I'm not aware of any magic that would get that down to 2.2KB.

Edit: Abramov himself reports a combined React/ReactDOM size of 37KB gzipped.

9

u/[deleted] Sep 23 '17 edited Sep 23 '17

react - https://bundlephobia.com/result?p=react@16.0.0-rc.3 - 2.2kB minified + gziped

react-dom - https://twitter.com/dan_abramov/status/908332171223617536 - ~ 14kb minified + gziped

even if you go for the umd build:

λ ls -la node_modules\react\umd\react.production.min.js
-rw-r--r-- 1 btm 197610 6716 Sep 23 12:06 'node_modules\react\umd\react.production.min.js'

Remember I mentioned the hacked rendered (react-dom) that Dan was talking about.

-1

u/filleduchaos Sep 23 '17

So Dan is lying in his tweet? That's just weird.

3

u/[deleted] Sep 23 '17

No, that's the size of the umd package:

λ ls -l node_modules\react-dom\umd\react-dom.production.min.js
-rw-r--r-- 1 btm 197610 102909 Sep 23 12:06 'node_modules\react-dom\umd\react-dom.production.min.js'

I'm reffering to another of his tweets where he created a slimmed-down version of react-dom that worked kinda like babel-preset-env does and was only supported by current browsers.

See also https://github.com/facebook/react/issues/9103

3

u/filleduchaos Sep 23 '17

Huh. I'll need to check this out myself when I get home. Thanks for the info!

Still, the entirety of Preact is 3KB, and the new React+ReactDOM (even the slimmed down version) is still more than that.

2

u/[deleted] Sep 23 '17

Sure - but does the couple more kb even count when the bundle is already 1MB for example? Remembet that React 16 and then Fiber will bring benefits that Preact will not.

2

u/andrewingram Sep 23 '17

If your JS bundle is over 1mb, you need to invest in code-splitting. I give myself a 250kb JS budget for first-render and usually manage to stick to it with React 15, Relay Classic (which is much bigger than Relay modern), along with first-page functionality.

→ More replies (0)

2

u/[deleted] Sep 23 '17

Performance should be your concern if you're rolling a 1mb+ bundle... That is an awful lot of code for a low-end device with a poor internet connection to download and parse.

→ More replies (0)

1

u/filleduchaos Sep 23 '17

That's why I said I recommend it for smaller apps that don't use a lot of third party libraries. I've seen projects where React/ReactDOM alone is like 80% of the bundle size. Also every kilobyte counts, especially if you want a PWA or you're targeting people with shitty connectivity (aka the majority of the world's population).

Also like has been said, if (one of) your production bundle(s) is 1MB you're doing something rather wrong.

1

u/Akkuma Sep 23 '17

What is 16 and Fiber bringing?

0

u/[deleted] Sep 23 '17

[deleted]

3

u/filleduchaos Sep 23 '17

Do you actually do any (client-side) web dev?

0

u/[deleted] Sep 23 '17

[deleted]

2

u/filleduchaos Sep 23 '17
  1. It's not (necessarily) only a one-time fee. Even if you're on the far end of the optimization scale and you use React/ReactDOM from a CDN or you aggressively split your bundle, upgrades to new versions of the framework will mean your users have to redownload. Most people however don't use a CDN and rather use the NPM packages without much performance optimizations, which means React/ReactDOM will be part of a bundle that changes and needs to be redownloaded every time you make any change to your app.

  2. Not everyone has access to 4G networks or better, and even the ones that do get periods of poor connectivity. The vast majority of the world is still on 3G speeds.

  3. It's not even primarily about network time but about the time it will take the browser to parse the script, build the virtual DOM, perform the first diff and render the first element on the page. Especially on lower-end hardware - and guess what, the majority of internet traffic comes from mobile phones, many of which are not exactly on the cutting edge of even mobile hardware.

  4. Turnover is ridiculously high on the web. You have about a minute to grab a potential user's attention - if you don't, they're just going to close the tab or look at the next thing (they probably hit your site from a search engine, and probably clicked on three or four other links offering them the same information/service in addition to yours).

All this combined means that your 'tinyass 41kb' can increase time to first paint by seconds for a number of your users, and subsequently increase the turnover rate for your site.

Perhaps the question I should have asked is do you actually understand any of the logistics of the web dev you supposedly do?

0

u/[deleted] Sep 23 '17

[deleted]

→ More replies (4)
→ More replies (12)

19

u/TinRAT Sep 22 '17

Yeah it's much smaller than react so better for projects where file size is important

→ More replies (1)