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

Server pre-rendering support #15

Open
aluxian opened this issue Jul 28, 2015 · 3 comments
Open

Server pre-rendering support #15

aluxian opened this issue Jul 28, 2015 · 3 comments

Comments

@aluxian
Copy link

aluxian commented Jul 28, 2015

I am using webpack and server pre-rendering. Halogen tries to access document and the server crashes:

/Users/aluxian/Projects/Fou/frontend/node_modules/halogen/node_modules/react-kit/getVendorPropertyName.js:3
var div = document.createElement('div');
          ^
ReferenceError: document is not defined
    at Object.<anonymous> (/Users/aluxian/Projects/Fou/frontend/node_modules/halogen/node_modules/react-kit/getVendorPropertyName.js:3:11)
    at Module._compile (module.js:430:26)
    at Object.Module._extensions..js (module.js:448:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/aluxian/Projects/Fou/frontend/node_modules/halogen/node_modules/react-kit/appendVendorPrefix.js:3:29)
    at Module._compile (module.js:430:26)
    at Object.Module._extensions..js (module.js:448:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/aluxian/Projects/Fou/frontend/node_modules/halogen/PulseLoader.js:2:14)
    at Module._compile (module.js:430:26)

I'd love to use it, but I can't.. is there a quick fix for this or would you have to take a deeper look and change how things work inside the components?

@joshhornby
Copy link

There is a hacky fix

const isBrowser = typeof window !== 'undefined';

render() {
      let spinner;

      if(isBrowser) {
        var Loader = require('halogen/ScaleLoader');
        spinner = ( <Loader color={this.props.colour} size={this.props.size} margin={this.props.margin} />);
      } else {
        spinner = (<div></div>);
      }

      return (
          <div>
               {spinner}
          </div>
      );
};

@ntucker
Copy link

ntucker commented Feb 19, 2016

+1

@raulanatol
Copy link

Waiting for yuanyan/domkit#7

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

No branches or pull requests

4 participants