-
Notifications
You must be signed in to change notification settings - Fork 46.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make React run without es5-sham #4189
Comments
I'm trying out implementing this myself. And I'm discovering some interesting quirks and possibilities. Firstly, in ES5 Object.freeze throws if given a non-object, in ES6 it returns it. Which means on one dev's machine in a browser implementing ES6 Which makes the React freeze stub a good place to even out the behaviour. Because calling Secondly, every place in code that uses Would it be good or unexpected to make React's internal freeze only run in dev? Last is a question. Do we want |
Shams are potentially dangerous and add 5kb of code, of which React requires almost nothing from (see facebook#4189). This commit. - Implements an internal Object.freeze stub that throws like ES5's object freeze and uses Object.freeze if it is implemented. - Implements an internal Object.create stub that only supports `create(prototype)`, the only Object.create behavior React requires. - Implements tests for both of these stubs. - Fixes React to use these stubs internally. - Removes the early Error thrown when either of these native or shamed methods are not available. - Removes reference of es5-sham.js from the docs. These stubs are implemented with consistency in mind so they will throw in the same conditions during development as they will when run in IE8. Tests which use Object.create or Object.freeze as part of the test have been left alone.
👍 I'd love this too, es5-sham doesn't interop very neatly with all libraries so I've ended up in weird situations where I (luckily) could include certain libraries before es5-sham and others after and have it sorted out that way. But I would really like not to have to use es5-sham at all. |
👍 |
1 similar comment
👍 |
React is going to fix this: facebook/react#4189
I submitted a fresh PR for review: #4959 The changes are very small and straightforward. |
Remove dependence on ES5 shams per #4189
Revert "Remove dependence on ES5 shams per #4189"
Remove dependence on ES5 shams per #4189
I'm ok with React requiring shims. I'd include them whether React needed them or not. However I don't believe React should require es5-sham to work. Because, among other reasons, including shams has the potential to break other libraries on the same page and hence doesn't sound like a good practice for one library to demand.
Of the two shams React says it requires (in the 0.14 code in npm) each one is only used once in the entire codebase.
2 function invocations doesn't sound like a good reason for requiring a 5kb library that has potential side effects.
The best practice for React would probably be to provide its own small module providing either the native function or an internal sham.
This would also be a positive. As these internal shams wouldn't have to waste bytes trying to sham functionality that React doesn't need. And they could emit invariant warnings when misused during development instead of failing (potentially silently) the way they would in es5-sham.
The text was updated successfully, but these errors were encountered: