jedireza / aqua

:bulb: A website and user system starter
https://jedireza.github.io/aqua/
MIT License
1.38k stars 356 forks source link

Using Modal component from a main page results in "window is not defined" error #241

Closed Cornstar23 closed 7 years ago

Cornstar23 commented 7 years ago

When trying to create an instance of Modal from, say, the client/main/navbar the server throws a "window is not defined" error. Is there something I might be doing wrong or is this a bug?

jedireza commented 7 years ago

Please include stack traces when sharing errors. window is not defined isn't that helpful on it's own.

I do know that the constructor of the Modal component expects the global window to be present, which doesn't exist on the server.

https://github.com/jedireza/aqua/blob/4e7cb75253a04e870b73e61a73842f896ecf983e/client/components/modal.jsx#L24

The main app is universal (aka isomorphic) and get's rendered on the server. You'd need to modify the Modal component to detect if global.window exists before using it.

Cornstar23 commented 7 years ago

Thanks. Not sure if the proper way, but I just moved

this.state = {
   bgHeight: window.innerHeight
};

to the componentDidMount() and set the bgHeight to 0 in the constructor instead of to window.innerHeight.

jedireza commented 7 years ago

If it works for you, that's all that matters. 😁