React, ClojureScript, and iOS 5
If you’re like me, you’ve only used React via ClojureScript and you’ve never had to download React directly. And honestly, this tidbit is pretty hidden:
At Facebook, we support older browsers, including IE8. We’ve had polyfills in place for a long time to allow us to write forward-thinking JS. This means we don’t have a bunch of hacks scattered throughout our codebase and we can still expect our code to “just work”. For example, instead of seeing +new Date(), we can just write Date.now(). Since the open source React is the same as what we use internally, we’ve carried over this philosophy of using forward thinking JS.
In addition to that philosophy, we’ve also taken the stance that we, as authors of a JS library, should not be shipping polyfills as a part of our library. If every library did this, there’s a good chance you’d be sending down the same polyfill multiple times, which could be a sizable chunk of dead code. If your product needs to support older browsers, chances are you’re already using something like es5-shim.
That’s from React’s Working with the Browser page. React uses some ES5 features that aren’t available in older browsers.
In my case, older browsers includes iOS 5, meaning without those polyfills first generation iPads do not work with React.
So if you’re trying to use React on a first generation iPad, it doesn’t work, and you see this delightfully helpful error in the debugger console:
Go grab es5-shim.js and es5-sham.js from https://github.com/es-shims/es5-shim and add them to your page before loading your app. Things’ll start working.