Closed ramusus closed 7 years ago
@ramusus Should this component work for server rendering?
Hi. This component is noly support browser side now. Welcome to pull a PR to support server rendering.
@ramusus I'm not convinced yet that we should add the change to React on Rails.
Actually I don't need to use the Checkbox component with server rendering. I use it in admin part, which doesn't require server rendering, but user facing part requires it strictly. For user facing part I have in initializers/react_on_rails.rb
config.prerender = true
And I disable prerender for admin:
<%= react_component('Admin', prerender: false) %>
And I got this error, when I try to load user facing index page and any other pages, except admin. So this problem is very important for me. Everything works well if I switch prerender off in config.
The problem line in my code:
import {Checkbox} from 'react-icheck';
If I remove it, error disappears. I think I cannot wrap it with try: catch
I found one workaround. Replace import with require and call in inside render:
render() {
const {Checkbox} = require('react-icheck');
return <Checkbox .../>;
},
Now it doesn't throw error.
@luqin I've added a PR for this issue here: https://github.com/luqin/react-icheck/pull/26 Based on my tests, this was the only blocker preventing server-side rendering
Thanks, now its solved
I've got this error working under react_on_rails app with
prerender=True
feature.It's easy to reproduce: import Checkbox in the component, which you are server pre-rendering.