Skip to content
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

[Feature Suggestion] Publish react also as ES2015 code #10164

Closed
Bnaya opened this issue Jul 12, 2017 · 11 comments
Closed

[Feature Suggestion] Publish react also as ES2015 code #10164

Bnaya opened this issue Jul 12, 2017 · 11 comments

Comments

@Bnaya
Copy link

Bnaya commented Jul 12, 2017

Do you want to request a feature or report a bug?
feature

What is the current behavior?
React is published to NPM only as ES5 code

What is the expected behavior?
Publish react also in es2015, with es2015 entry point in the package.json

Motivation: Performance. leverage the targeted client native ES features
Its part of the angular 4 package format
https://docs.google.com/document/d/1CZC2rcpxffTDfRDs6p1cfbmKNLA6x5O-NtkJglDaBVs/edit#heading=h.jt2mvxhyrshv
http://2ality.com/2017/04/setting-up-multi-platform-packages.html

@gaearon
Copy link
Collaborator

gaearon commented Jul 12, 2017

This sounds like a duplicate of #10021.

But it is not clear to me which performance benefits you are expecting in particular. If you could expand in that issue that would help.

@gaearon gaearon closed this as completed Jul 12, 2017
@Bnaya
Copy link
Author

Bnaya commented Jul 13, 2017

#10021 Is about shipping react with es2015 modules but ES5 syntax, for tree shaking.

This issue is about shipping react also with es2015, so the consumer will be able to transpile it using https://github.com/babel/babel-preset-env as part of his project.
That way the browser will run arrow functions, classes and other ES6 features natively and not transpiled code. (better for performance, debugging)

@gaearon gaearon reopened this Jul 13, 2017
@gaearon
Copy link
Collaborator

gaearon commented Jul 13, 2017

Ah, I see what you mean now.

better for performance

Can you point me to related benchmarks? As far as I’m aware ES6 features are still slower in the mainstream browsers than ES5 counterparts.

Additionally React 16 won’t really be using either classes or arrow functions in its code, so I’m not convinced this makes a lot of difference for debugging.

@geelen
Copy link

geelen commented Aug 15, 2017

I'd like to add my vote for this, just cause I've been playing around with in-browser ES modules today. Currently, on the Installation page you can download a HTML file with this code in it:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Hello World</title>
    <script src="https://unpkg.com/react@latest/dist/react.js"></script>
    <script src="https://unpkg.com/react-dom@latest/dist/react-dom.js"></script>
    <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
  </head>
  <body>
    <div id="root"></div>
    <script type="text/babel">

      ReactDOM.render(
        <h1>Hello, world!</h1>,
        document.getElementById('root')
      );

    </script>
  </body>
</html>

It would be cool if you could do instead:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Hello World</title>
  </head>
  <body>
    <div id="root"></div>
    <script type="module">
      import React from 'https://unpkg.com/react@latest/dist/react.module.js'
      import ReactDOM from 'https://unpkg.com/react-dom@latest/dist/react-dom.module.js'

      ReactDOM.render(
        React.createElement('h1', null, 'Hello, world!'),
        document.getElementById('root')
      );

    </script>
  </body>
</html>

Not much you can do about the JSX but still, might be interesting to someone!

@gaearon
Copy link
Collaborator

gaearon commented Aug 15, 2017

I think this issue is about slightly different thing. The one you're looking for is #10021.

@geelen
Copy link

geelen commented Aug 15, 2017

I... don't think it is. I don't want untranspiled source, I want a bundle, flattened like normal, to have ES modules exports.

P.s. I thought you were on holiday Dan 😉

@gaearon
Copy link
Collaborator

gaearon commented Aug 15, 2017

I think it's the other way around :-) #10021 is about modules. This issue is about untranspiled source: #10164 (comment).

Going back to vacation!

@betaorbust
Copy link

betaorbust commented Oct 4, 2017

better for performance

My guess is, he’s talking about the over-the-wire bundle size vs runtime perf.

Additionally React 16 won’t really be using either classes or arrow functions in its code, so I’m not convinced this makes a lot of difference for debugging.

This is actually really important to this topic. I ran some tests this weekend where I swapped out the Closure compiler ES5 target for the ES2015 one, but, because Closure’s ES2015 is not anywhere as efficient as the insane magic that is its ES5, the bundle size actually went up. I also tried babel-minify with similar results. Uglify doesn’t support ES2015.

On most projects, this isn’t the case, and you can see up to 50% payload reduction because you don’t have all the Babel helpers, large transpiled results, etc. But for React specifically it’s not a win because React’s codebase uses so little of the expensive (size-wise after transpilation) ES2015 syntax.

While the module discussion in the other topic might be good to keep alive, I think we can close this one out for now. Due to the lack of anything approaching with the current efficiency of Closure ES5, React can’t currently get any wins from delivering in ES2015 — as it’s mostly ES5 to begin with!

@gaearon
Copy link
Collaborator

gaearon commented Oct 4, 2017

But for React specifically it’s not a win because React’s codebase uses so little of the expensive (size-wise) ES2015 syntax.

That's my impression too.

@artalar
Copy link

artalar commented Apr 20, 2018

@gaearon
Please, look at this benchmark
https://jsperf.com/arguments-calculation/1
(i have 20x difference)
And at this code
https://github.com/facebook/react/blob/master/packages/react/src/ReactElement.js#L210
createElement is mostly callable function and it can be increased in performance

@gaearon
Copy link
Collaborator

gaearon commented Apr 20, 2018

Tiny benchmarks like this are not representative of real code performance.
For example:

https://mrale.ph/blog/2014/12/24/array-length-caching.html

If you can prepare a reproducing case that involves a real (even a small) React app and also demonstrates a stark difference it would be interesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants