kvendrik / intercom-react

💬 An Intercom component for React.
19 stars 4 forks source link

Server-side rendering #8

Closed oyeanuj closed 5 years ago

oyeanuj commented 6 years ago

Hi @kvendrik! As I was playing with this, I am seeing errors on the server side since the window object is not available on the server:

SERVER: ERROR in server execution:
ReferenceError: window is not defined

I assume a check is needed to see if the window object is defined and if not, aborting early?

kvendrik commented 6 years ago

Hey @oyeanuj!

Hmm interesting as the component doesn't seem to use window anywhere except for within the frame. This might need some further exploration.

I currently don't have time to contribute to the component but as mentioned in the other issue: if you'd like to use this feel free to contribute, I'm happy to answer any questions you may have. 🙂

oyeanuj commented 6 years ago

Thanks for the quick response! I think the window object might be used by the Intercom API itself. The react-intercom component has a check to see if DOM can be used before proceeding further:

https://github.com/nhagen/react-intercom/blob/913b41107c43fc942f27b7cb7f6a0a575eb913b0/src/index.js#L3

kvendrik commented 6 years ago

I feel like in their case the check is mainly there because they're directly referencing window.Intercom whereas we wait until the iframe has been loaded. I might be wrong though and I wonder where the window reference that is throwing the error in our case lives.

kvendrik commented 5 years ago

Update: the library doesn't reference window anywhere directly, therefor I'm not sure this is caused by the library. I'll close the issue for now, if more SSR issues pop up we can reopen it.