Setting React Variant To Production Has No Effect
Help us help you! Please choose one:
- [ ] My app crashes with
react-rails, so I've included the stack trace and the exact steps which make it crash. - [ ] My app doesn't crash, but I'm getting unexpected behavior. So, I've described the unexpected behavior and suggested a new behavior.
- [ ] I'm trying to use
react-railswith another library, but I'm having trouble. I've described my JavaScript management setup (eg, Sprockets, Webpack...), how I'm trying to use this other library, and why it's not working. - [X] I have another issue to discuss.
I have changed my variant to production in production.rb with config.react.variant = :production. However, I still get a warning when I push to heroku to my production build that I am using a development version of react.
Hi, are you using webpacker or sprockets to build your javascripts?
Sprockets. Should I switch to webpacker?
Sprockets is OK! That setting should work for Sprockets ...
Just to be sure, is there any other setting in application.rb ? (I can't remember which takes precedent.)
Also, which version of react-rails are you using? Some past versions didn't have the right React.js files :S
Nothing in application.rb (at least not related). I just switched to version 2.2 and still having the issue.
I'm seeing the same behavior.
#config/environments/production.rb
Rails.application.configure do
...
config.react.variant = :production
end
still packages the development build when using sprockets/asset pipeline.
This is still happening, gem version 2.2.1
I was having the same issue, but it was because of browserify-rails with node_modules.
@Bevilacqua, @boxofmattwire or @dklanac is it still happening? Sorry to bother after so long but trying to catch up maintaining.
I wonder if sometimes it's to do with the sprockets cache, worth a rake tmp:clear every now and then.
Going to close this if I hear nothing for a week as the issue is going stale, will reopen if this is still an issue.
I've upgraded to 2.3.1. I'm going to give it another shot today.
After upgrading, I did a quick test in my local dev by changing the variant setting to :production within development.rb. I also clobbered my assets and cleared out my node_modules folder for good measure.
I'm still rendering the development build after making these changes.
Edit:
I hardcoded the production variant within lib/react/rails/asset_variant.rb on line 21 and still receive the development build.
@react_build = 'production'
@dklanac can you produce some small reproduction of the issue, or maybe some example code?
I'm struggling to help as I tried to replicate your issue here:
https://github.com/BookOfGreg/react-rails-example-app/pull/3
Where I changed the config.react.version to production in my development.rb and it did change.

That example is using React-Rails 2.4.0, Sprockets 3.7.1
Thanks for posting this @BookOfGreg. I'm still running into my issue. From what I can tell, here are the key differences from the example app that I see: Mine || Example
- Browserify || Webpack
- react-rails (2.2.1) || 2.4.0
- Rails 4.2 || Rails 5.1
I'm running sprockets 3.7.1 too.
Maybe there's a config setting that I'm missing with browserify that is there by default for webpack?
Ooh, this is a good opportunity for me, how are people using browserify with react-rails? Do you have a sample, or can point to a repo/blog that is?
If you have an example I'd love to add it as a branch of my example app so I can test these things on it, there are a couple other issues open related to browserify I have so far failed to reproduce too.
I'll try react-rails 2.2, rails 4.2, browserify tonight to see if I can reproduce this one.
+1
I was also receiving the This page is using the development build of React. message on a Rails 4.2 project with react-rails (through the Asset Pipeline) that I am working on.
After some debugging, I opened the source code on my browser on a rendered page and noticed that my app was loading React v15.6.1, while https://github.com/reactjs/react-rails/blob/master/VERSIONS.md claims that my version of react-rails should be React 16.x! I was like 'whaaat?'.
Grepping 'React v15.6.1' on my gems folder made me realize that another gem I am using has React as dependency. On my Gemfile I found:
source 'https://rails-assets.org' do
gem 'rails-assets-react-bootstrap', '~> 0.31'
end
This gem required rails-assets-react (15.6.1), so when I added //= require react on my application.js, I was actually loading rails-assets-react, and not react-rails!
But I'm not sure how to solve it. Is there a way to specify from where Sprockets should load the file when I //= require react?
@dklanac maybe you can also check if you have a similar problem (another gem loading another version of React).
If both gems are serving their own React then the most reliable way of guaranteeing which one you get is to vendor your own. Sprockets should be smart enough to always load the one from vendor/assets before a gem's implicit one (If I understand their load order correctly).
https://github.com/rails/sprockets/blob/cb390301071c17f6f346e4abefb9f4e09f890e3f/guides/building_an_asset_processing_framework.md#manipulating-the-load-path
This gem serves one version of React for people who do not want to vendor their own but if you have any other react deps, it's probably worth controlling the version of it by hand explicitly.
👀
@ttanimichi has a good point. This is not an issue, people using browserify need to contribute if it's to be documented or supported. Works as intended on sprockets. Closing for now. Will re-open if there is additional feedback.
Hi there i am having the same problem, using reactjs (react-rails 2.4.7) through rails asset pipeline I found that i must have:
config.after_initialize do
config.assets.paths = config.assets.paths -
config.assets.paths.select {|e| e.to_s =~ /lib\/assets\/react-source\/development/}
end if Rails.env.production?
in config/application.rb in order to get production variant in production... This might be,because even in production you gets react-source/development and react-source/production in assets path and the first gets precedence... anyway, lib/assets/react-source/development should not exist as an asset path in production...
@mpantel, Are you still facing this issue? @BookOfGreg We have reopened this issue. Let's wait for @mpantel response.
Let's close the issue.