hypernova-react icon indicating copy to clipboard operation
hypernova-react copied to clipboard

is reactDOMServer loaded on the browser?

Open yinghaochan opened this issue 8 years ago • 8 comments

RenderReact imports reactDOMServer here: https://github.com/airbnb/hypernova-react/blob/master/src/index.js#L3

Your example bundles

var React = require('react');
var renderReact = require('hypernova-react').renderReact;

function MyComponent(props) {
  return React.createElement('div', {
    onClick: function () {
      alert('Click handlers work.');
    },
  }, 'Hello, ' + props.name + '!');
}

module.exports = renderReact('MyComponent.js', MyComponent);

into the rails application using sprockets.

Does this mean the client browser is always loading reactDOMServer?

yinghaochan avatar Dec 09 '16 06:12 yinghaochan

@yinghaochan yes

goatslacker avatar Dec 12 '16 22:12 goatslacker

@goatslacker @ljharb Is this something that is supposed to be changed at some point? Loading server centralized code on the client does not seem to be that productive.

Inkdpixels avatar Aug 31 '17 13:08 Inkdpixels

You can always alias out that import in your bundler.

I suppose we could lazy-require it?

ljharb avatar Aug 31 '17 15:08 ljharb

Yep I guess lazy-requiring it would be a good solution, while aliasing it is also an option this pushes the work to the user IMO. I could submit a PR for it if you haven't started working on it yet :)

Inkdpixels avatar Aug 31 '17 15:08 Inkdpixels

While lazy requiring it is better than the current approach it's still a half solution...the bytes will still end up in the user's browser. How about we figure out a way to not require it at all?

goatslacker avatar Sep 07 '17 17:09 goatslacker

Not if it was wrapped in a process.env check that could be uglified out.

That said, splitting the server and client code into separate entry points might be the better solution.

ljharb avatar Sep 07 '17 19:09 ljharb

getting it started, should we break current implementations? -> https://github.com/airbnb/hypernova-react/pull/45

wingleung avatar May 10 '18 16:05 wingleung

If this problem was solved hypernova could also support loadable components, which require some custom chunk loading logic where you need to require a file on the server.

But you can't have "path" imports etc on the client. I'm not sure how that can be achieved. The file splitting is a start, but it doesn't solve the actual problem of code sharing.

gempir avatar Feb 13 '23 10:02 gempir