r/angularjs • • Jun 30 '18

Why React is bad.

Here's why I think Angular is much better than React for creating SPAs.

React is not a framework like Angular is. It doesn't provide a comprehensive, one stop solution for all the things that you need for building an SPA. Often you will hear that React is 'un-opinionated' and that it allows developers the freedom to use whatever technologies they want alongside it. In practise, this means having to either constantly reinvent the wheel, or else employ a hotchpotch of third party libraries and be completely at the mercy of their maintainers.

Third party libraries may be buggy and there's no guarantee that fixes will be swift, if they even happen at all. Plus, they may be deprecated without any notice and you have to hope that they will work together successfully.

For state management Redux is the defacto standard. Redux is, in my view, seriously flawed. Firstly, why do you need to have a store in your client side at all? Is that not what the Database is for? In an SPA, the URL should be the single source of truth and the entire state of the app should be derived from this, using data fetched from a service. When you use Redux in an SPA, you need to work to keep the store in sync with the URL. This is a lot of work for no obvious benefit.

Another problem is that it risks storing stale data. Once the URL changes, all the existing data is potentially stale. There is no value in storing data across requests. If you want to cache data, the browser will cache your requests. Invalidating caches is notoriously difficult to do - why on earth do we bring this problem to client side development!

Redux also introduces Race conditions. If we make multiple requests to the server in quick succession, the Redux store has no way of knowing in what order these were made and given that they can return in any order, it is quite possible that the page we are looking at could be overwritten by the data from an old request! More detail about this problem here:http://blog.richardhunter.co.uk/index.php/13

The Redux store does NOT represent the current state of your app. It probably contains it, but it contains an awful lot besides and working out what is the current state and what is old state involves a lot of error prone work.

The next problem with React is that it does not support Dependency Injection. https://en.wikipedia.org/wiki/Dependency_injection DI is essential for building a complex enterprise grade application. The main benefits of DI are that it makes object creation a much cleaner process and it decouples dependencies from their implementation. If the last point is unclear, what it means that when you build an object you can supply completely different objects for any particular dependency. This is useful in testing where you can swap in mock objects for dependencies and thus test your objects in isolation from each other. With React, you have to rely on monkey patching or else test much larger chunks of your code at a time.

In React, you have to pass any dependencies down to components through props which can mean that a component has props that it doesn't actually use itself but just has them so it can pass them down to child components. You can use the Context for surfacing dependencies in a component but this is very much a poor man's DI imho.

There are other things about React that I don't like, but I don't want to extend this post too much. In particular PropTypes seem like an extremely feeble way of doing static typing and really typifies what is bad about React.

React isn't just different for not being a framework - it's worse. It is hopelessly inadequate for doing the job that it is supposed to and just results in messy, buggy, and inadequately tested applications.

I think the reason that React is more popular than Angular is because Angular lost a lot of good will during the shift from version 1 to 2. Maybe the Angular team didn't cover itself in glory, but I think the decision was the right one as the new Angular is much superior to the old one. It's irrational to dislike Angular because of these events but maybe a lot of developers are irrational.

0 Upvotes

122 comments sorted by

View all comments

Show parent comments

1

u/[deleted] Jun 30 '18

I didn't recommend storing personal details in the browser cache, but I'm curious, what is the massive security hole in doing so?

1

u/prof_hobart Jun 30 '18

I'll repeat my question "Where do you think a browser caches its data?".

-1

u/[deleted] Jun 30 '18

No, you answer the question. You're the one making the claim.

1

u/prof_hobart Jun 30 '18

Oh dear. OK as you don't seem to know, and don't seem interested to bother to even look it up, they are stored in files on the computer.

If, for example, one of your users happened to use a shared computer to access your site, that data is now available to anyone else who happens to use the same computer.

Can I ask what kind of sites you work on?

1

u/[deleted] Jun 30 '18

And they're not encrypted?

1

u/prof_hobart Jun 30 '18

They might be on some browser implementations. But if they are, the key to decrypt them has to be available to the browser, and therefore to anyone who's got access to the machine.

I'll ask again - what kind of sites do you work on? I'm concerned if your work involves any type of sensitive data and your security teams haven't already explained this all to you.

1

u/[deleted] Jun 30 '18 edited Jun 30 '18

So you don't actually know if they're encrypted or not then. Quelle surprise.

1

u/CommonMisspellingBot Jun 30 '18

Hey, Richardinho76, just a quick heads-up:
suprise is actually spelled surprise. You can remember it by begins with sur-.
Have a nice day!

The parent commenter can reply with 'delete' to delete this comment.

1

u/prof_hobart Jun 30 '18

I don't know the full capabilities of every possible browser that my users might be on, no.

But I do know, as I explained, that for any browsers that do bother to encrypt it, that would be pretty much irrelevant to someone trying to steal the info off a shared computer as the key is already on there.

Stop trying to pretend that it's a good idea to store sensitive information in a cache file stored on a user's PC. It's not.

And you're still not answering my question about the kind of software you work on.

-1

u/[deleted] Jun 30 '18

Maybe you weren't paying attention when I said that I wouldn't recommend storing sensitive data in the browser cache. Maybe you're just setting up a straw-man to cover your arse. Not sure why you think it's somehow magically safer in a Redux store. Maybe you have an answer to that.

1

u/prof_hobart Jun 30 '18 edited Jun 30 '18

Err, you claimed that I was "making stuff up" when I pointed out that it wasn't a good idea. And why have you spent about 6 posts trying to challenge why it's not safe if you also don't think it's a good idea? And why, specifically don't you think it's a good idea?

Not sure why you think it's somehow magically safer in a Redux store.

Because that's not stored on files on the local machine that will live on after you've logged out or closed the browser down? The Redux store is simply a JS object attached to a window. If any of your data is going anywhere near any client-side JS (which it will be if you're using using Angular), it's going into a JS object in the same sort of way.

And you're still not answering my question about the kind of software you work on.

→ More replies (0)

1

u/ianwcarlson Jun 30 '18

The browser cache is stored as files on the host machine. A hacker would need to log into that user's account on the machine or have root privileges. I think it's valid to say never storing sensitive information in the browser cache is safer. But I think most security analysts would agree that if someone can log into your machine and/or has root access, you're gonna get pwn'd no matter what.

1

u/[deleted] Jun 30 '18

It would be encrypted though, presumably?

1

u/ianwcarlson Jun 30 '18 edited Jun 30 '18

It's not: https://groups.google.com/a/chromium.org/forum/#!topic/security-dev/TXdm-ygu__o

Even if it were encrypted, it would only help with a small set of attacks. The only real security is full-disk encryption with a really good password.

1

u/[deleted] Jun 30 '18

Thanks. It's pretty obvious that you have to be careful with sensitive data but its interesting to hear the underlying details.