-
Notifications
You must be signed in to change notification settings - Fork 265
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
ReferenceError: window is not defined - Server-Side Rendering (SSR) #40
Comments
Hi @KrzysztofKarol, thank you for reporting this! I was actually unaware of how/if this library worked with SSR. As a workaround until this is implemented you could maybe render the tree on |
Hi @bkrem Thank you for your almost instantaneous answer.
I investigated problem a little
|
Ahh interesting, thanks for digging into this already. Seems like the least path of resistance would be to set If you have an idea feel free to put in a PR @KrzysztofKarol, otherwise I'll check this out in detail this evening :) |
I couldn't find simple and good solution. So i made it very dirty way for now - I used isomorphic-style-loader instead of style-loader. BTW. I also encountered a problem with |
Ok cool, good to hear you found a way. If Ok that's a strange one regarding Thanks for reporting these two already, super useful! 🙌 |
@bkrem @KrzysztofKarol Is this issue fixed? Somehow I'm still seeing the same error during server side rendering. amazing work by the way, looking forward to using it! |
Hi @codemonkeycxy! I wasn't using this lib for months so you have to ask @bkrem directly. |
Hi @codemonkeycxy, SSR still isn't technically supported. I spent an entire day at the time tinkering with the isomorphic loader that Krzysztof suggested (and one or two other ones). I couldn't get a stable version out of it and there were more pressing issues to resolve with the library so I closed this as out of scope (sorry for my lack of explanation when I closed it), since this error is preventable if you await class MyTreeComponent extends React.PureComponent {
state = {
didMount: false
}
componentDidMount() {
this.setState({
didMount: true
})
}
render() {
<div>{this.state.didMount && <Tree />}</div>
}
} I'm aware that this isn't optimal ( I hope this helps as a workaround for now and I will obviously update the issue once a fix is in place! |
@codemonkeycxy you can also use npm's package react-no-ssr as a workaround https://github.com/kadirahq/react-no-ssr/blob/master/src/index.js |
@KrzysztofKarol How is this meant to be used? I see it's a component on NPM now, but I'm still getting window is not defined when used like: const Root = () => (
<Provider store={store}>
<NoSSR>
<ComponentThatUsesWindow />
</NoSSR>
</Provider>
) |
@thomashibbard I think yes but this repo has latest commit dated on 9 Apr 2016 so I don't know how does it work with latest React versions. |
@thomashibbard same window not defined issue even with NoSSR. I finally got it working by doing a inline import
|
this worked for me |
If anyone is still strugling ? For Imports For Usage Function (canUseDOM) |
Any update with integration of this to Gatsby? |
How to use this great library properly with Server-Side Rendering (SSR)
return window&&document&&document.all&&!window.atob
The text was updated successfully, but these errors were encountered: