Akshay Borade
Akshay Borade

Reputation: 2472

React-rails: Component with { prerender: true } issue

I'm using the react-rails gem in a project.

Whenever I pass in the {prerender: true} in react_component helper, I am getting this error :

Encountered error "ReferenceError: ReactDOMServer is not defined" when prerendering UsersList with

Upvotes: 1

Views: 2634

Answers (1)

Benigno H
Benigno H

Reputation: 66

I have the same issue and haven't found a proper solution. I created an issue on the github repo of the gem. So far there's a workaround (for an other issue but it worked for me):

Copy/pasted from issue #443

  1. Make sure components.js is compiled (Rails.application.config.assets.precompile += %w( components.js ))
  2. Add //= require react-server to your components.js file
  3. Specify only components.js for server rendering:

    config.react.server_renderer_options = { files: ["components.js"], # files to load for prerendering }

UPDATE:

Downgrading the following gems: sprockets (2.12.4) and sprockets-rails (2.3.3) seems to avoid the issue.

Upvotes: 5

Related Questions