Live data from Hacker News

Etsy Moves from React to Preact

github.com

41–50 of 71 posts

Re: Etsy Moves from React to Preact

#41
post #31

Earlier quoted context omitted.

Would also like to know why! The old AngularJS was pretty horrible in my experience, but Angular 2+ was leaps and bounds better! As a "batteries included" framework i prefer it to the alternatives that one would typically consider for front end development instead: React, Vue, Svelte etc. (though i would pick Vue/Svelte for more lightweight sites and maybe React because of its ecosystem) That said, it still is pretty…

> To me, using TypeScript in React just felt needlessly cumbersome, especially with functional/hook based components. Out of curiosity: can you explain how/why? My experience has been quite simple, especially if only using functional components and hooks: interface Props { prop1: string; prop2: number; } const Component : React.FC = ({prop1, prop2}) => { // types are inferred correctly } Hooks have been similarly eas…

It's been a little while since i had to work in the React + TypeScript project (nowadays use Vue more often) so it's not fresh in my memory, but sure!

For starters, even your example shows the awkwardness somewhat, it is essentially the same as writing the following (if you don't need the interface elsewhere):

  const Component: React.FC =
  ({prop1, prop2}) => {
      return ...
  }
Suppose i want to add a new property: now i need to do it in two places (the interface definition, with either syntax). Want to remove one? Same story. Rename one? Sure, your IDE should let you do this, but the change is still necessary in two places. Why couldn't i do something like this instead (the answer is that the language is just not structured that way, but clearly having duplication for no good reason whatsoever isn't nice):

  const Component: React.FC(prop1: string, prop2: number) => {
      return ...
  }
  
  or
  
  const Component: React.FC(props: Props) => {
      return ...
  }
Contrast that with a pure JS implementation (which is bad because it doesn't tell you about the individual props or their types, but surely one can also imagine just a list of different prop parameters):

  function Component(props) {
      return ...
  }
Of course, that's more of a nitpick, but the code often reads worse than Java does in my eyes.

Another thing that i disliked was working with union types, especially when you're stuck with loosely defined objects in a legacy codebase, where you can't always work with properly structured definitions of "this one thing is a union of BASE FIELDS but also ADDITIONAL FIELDS FOR ENTITY TYPE A that won't be defined in separate places, because if we split it up for some reason this one library integration will fail to render UI components properly".

I started writing out more about that particular case, but realized that articulating precisely what was the problem in it and diving back into that older codebase to recreate code examples would take time and sadly i don't really care for doing that. But hey, JavaScript would let you just wing it and check each field individually before trying to access them, so you could let the code decide the behavior, not the type system, which is sometimes the path of least resistance. Personally, i think that strong type systems are always good in the back end, but i feel less strongly in that regard about front ends.

Also, i'm not sure that building TypeScript on top of JavaScript was the best idea: surely from a support/target platform perspective it was brilliant, but sometimes you get all sorts of awkwardness.

For example, the React TypeScript bindings themselves have something like the following:

  type Booleanish = boolean | 'true' | 'false';
Oh, and in regards to TypeScript in particular (though this is also annoying in Angular etc.), their implementation of even enums is awkward. Consider that in Java you can easily turn any string into an enum value if possible and can also have enums act as containers for additional data, for example: https://www.tutorialspoint.com/how-to-convert-a-string-to-an...

Re: Etsy Moves from React to Preact

#42
post #30

Earlier quoted context omitted.

> Minification or not, starting with a 6x bundle size puts you in a precarious position to have to care more about how it grows over time adding other assets. If this were true, wouldn't it apply in equal measure to other resources? And if that's true, then why do we still see multiple MB large pages that are full of images or even videos? Personally, the arguments expressed in "The Website Obesity Crisis" back in 20…

> If this were true, wouldn't it apply in equal measure to other resources? No. On sites that buy in to react/preact, there are parts of the site that won't work until react/preact has loaded. In contrast, the site will work perfectly fine without having loaded those large beautiful images. If done correctly, images won't even affect the layout of the page. Likewise, it doesn't matter if google analytics and the 10 t…

The "if done right" portions of the comment are huge ifs though and almost no one does it right.

Re: Etsy Moves from React to Preact

#43
I think the biggest problem with this is that Preact is not a 100% drop-in replacement for React. The devil is in the details. The programmers will casually follow online answers from stackoverflow or blog post regarding React and apply them to the Preact project. This will work more often than not, but from time to time you can run strange bugs, which only happens on Preact and it takes much time to detect and debug them.

Re: Etsy Moves from React to Preact

#44
post #40

One thing I don't understand about the JS ecosystem in general is the focus on minified size. This article does the same thing: preact is 6k or so whereas react is 36k. This comparison seems entirely pointless when the first page load downloads multiple megabytes of assets and, additionally, a lot of users would have React in their browser cache anyway.

> a lot of users would have React in their browser cache anyway. Do browsers share cache across domains? Seems like an easy vector to poison.

Nope https://news.ycombinator.com/item?id=30136221

Re: Etsy Moves from React to Preact

#45
post #32
post #7

Earlier quoted context omitted.

Do you mind to share why?

Mostly I have various stylistic misgivings with Angular. I feel like I spend a lot of time on ceremony and piles of RxJS that would've just been simple function calls in React, which is what I did before. There are some things related to state management, especially module initialization, that it seems to me is a leading to a lot of code bloat to handle an initial state with null state that shouldn't actually ever ex…

Heh, this seems like a case of different people having completely opposite experiences.

Had to work on an Angular project or two, they were largely passable and didn't cause too many problems. Admittedly felt a bit close to writing back end code at times, even - pretty boring and predictable. In Angular the type system was also reasonably easy to use, even with things like non-nullable/nullable/optional values etc.

Had to work on a few React projects, the JavaScript ones were pleasant to work with and develop (seriously, React's functional components are an amazing time saver for display components), but as soon as you introduced TypeScript and Redux as well as plenty of hooks and even custom hooks, it went down the drain.

Perhaps that's a bit what you're experiencing with RxJS, which adds a ton of complexity in of itself - being able to start with just Angular and go from there (or in my case - using MobX instead of Redux which is just so much nicer to use) might have been more passable.

Actually made a sibling comment like this, though it's not as detailed as i'd like: https://news.ycombinator.com/item?id=30220131

But hey, good luck with bending Angular to your will! If nothing else, i can acknowledge many codebases out there being a mess!

Re: Etsy Moves from React to Preact

#46

I think the biggest problem with this is that Preact is not a 100% drop-in replacement for React. The devil is in the details. The programmers will casually follow online answers from stackoverflow or blog post regarding React and apply them to the Preact project. This will work more often than not, but from time to time you can run strange bugs, which only happens on Preact and it takes much time to detect and debug…

I built a product with Preact, and can’t think of any time it’s bitten us like that. I’m sure you’re right, but for us at least, it’s been smooth sailing.

Re: Etsy Moves from React to Preact

#47

So Etsy wants to replace a core part of their frontend tooling to save 30KB in bundle size?

You clearly didn't read the article. It mentions that in addition to the (relatively small) bundle size savings, the version of Preact they were investigating (as of 2020 when it was written) was also more compatible with the current version of React they were using at the time than the newest version of React (15 -> 16 had a lot of breaking changes). I don't believe the bundle size was really a major contributor to…

Doesn't explain why they could not have continued using React 15.

Re: Etsy Moves from React to Preact

#48
post #30

Earlier quoted context omitted.

> If this were true, wouldn't it apply in equal measure to other resources? No. On sites that buy in to react/preact, there are parts of the site that won't work until react/preact has loaded. In contrast, the site will work perfectly fine without having loaded those large beautiful images. If done correctly, images won't even affect the layout of the page. Likewise, it doesn't matter if google analytics and the 10 t…

> Likewise, it doesn't matter if google analytics and the 10 thousand myriad tracking pixels take a minute to load: users shouldn't notice any difference here. So much for me being able to open 100-200 tabs across all windows on my browser without needing more RAM. Or even using a browser on my older phone without it feeling slow/sluggish or the browser killing the battery life of the device. To clarify for the downv…

Hey, I said "users", not "evil hackers doing weird things" ;)

The sad thing is that this isn't entirely a joke. I've brought up those kind of issues in executive meetings in the past (trying to exterminate battery-draining animations being a particular crusade of mine).

The response is a mix of blank stares, mild interest... and a quick dismissal from the top dog in the room, along the lines of: "That's certainly something to consider, but I think we have more pressing matters in our hands. Let's keep these on the back burner."

I don't even try anymore :(

Re: Etsy Moves from React to Preact

#49
post #48

Earlier quoted context omitted.

> Likewise, it doesn't matter if google analytics and the 10 thousand myriad tracking pixels take a minute to load: users shouldn't notice any difference here. So much for me being able to open 100-200 tabs across all windows on my browser without needing more RAM. Or even using a browser on my older phone without it feeling slow/sluggish or the browser killing the battery life of the device. To clarify for the downv…

Hey, I said "users", not "evil hackers doing weird things" ;) The sad thing is that this isn't entirely a joke. I've brought up those kind of issues in executive meetings in the past (trying to exterminate battery-draining animations being a particular crusade of mine). The response is a mix of blank stares, mild interest... and a quick dismissal from the top dog in the room, along the lines of: "That's certainly som…

I've definitely run into this in my own past as well. On one hand, you can understand the business incentives - ship something relatively quickly, have it look good enough to attract attention or at least not scare anyone away.

For example, compare the front pages of SourceHut (a lovely and lightweight project) https://sourcehut.org/ and GitLab (a really good self-hostable solution with plenty of features) https://about.gitlab.com/

One of those would capture the attention of most people better, so that's what the market will optimize for at large, unfortunately also sometimes pushing focusing on other things with less visibility (to the average user) to the back.

For the simpler things, not asking for permission can be a good idea (depending on the environment and circumstances) - a line that i heard in a software development conference once was: "You don't ask your manager for permission to write tests for your code, so why should you for making other similar decisions that are essentially just doing your job well?"

Of course, then you also become responsible for the potential impact of those changes and things going wrong, so it works better on simpler cases/optimizations and only as long as the things you're changing are simple enough to have almost no impactful bugs or you have enough tests in place to catch any.

Other times you can succeed by adopting a data driven approach and a healthy helping of taking initiative: "Hey, our automated performance tests indicate a regression in page load times of X% after version Y, which, according to these random but serious looking studies and posts might result in lost potential conversions and could cost us Z$ the following year. I've described these problems and what to do in Jira issue #W and have escalated the priority to 2, so that's what i plan on doing this week. Any questions?"

Re: Etsy Moves from React to Preact

#50

I wonder what the other differences and considerations are. The article is focused on issues that might arise from switching, but does not really cover the “why” of switching beyond bundle size. A valid reason, but I assume there is something to say for React or is it really that similar that switching is a no brainer?

The way I read the document is that the main reason is that they do not have to upgrade their whole stack including dependencies like React Router. Stepping off the dependency upgrade treadmill is an interesting and valid point that I think many HN readers dream of. It seems to me that Etsy has ended up so far behind current React that going to Preact is a very valid direction to take.

I'm not sure I read that in the article.

I also don't see why switching to Preact does not require updating, they even mention they will have to do this anyway, including some of their routing dependencies. Preact seems to be keen on keeping compatibility with React, referring to the current and previous versions, so it is very likely updates need to happen regardless.

Also, upgrading React is usually not too much effort as for most changes codemods are provided that do most of the work. Not saying it doesn't require effort at scale, but I don't see or read how Preact would make that any easier. Considering you'll use React libraries in Preact I would be worried about upgrading and compatibility later on.

I'm honestly interested as the lower bundle size is significant, but I'd like to know the other pros/cons and risks that surely are there.

Post reply on HN