react-rails icon indicating copy to clipboard operation
react-rails copied to clipboard

Setting React Variant To Production Has No Effect

Open Bevilacqua opened this issue 8 years ago • 19 comments

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-rails with 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.

Bevilacqua avatar May 15 '17 18:05 Bevilacqua

Hi, are you using webpacker or sprockets to build your javascripts?

rmosolgo avatar May 15 '17 18:05 rmosolgo

Sprockets. Should I switch to webpacker?

Bevilacqua avatar May 15 '17 20:05 Bevilacqua

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

rmosolgo avatar May 16 '17 14:05 rmosolgo

Nothing in application.rb (at least not related). I just switched to version 2.2 and still having the issue.

Bevilacqua avatar May 16 '17 14:05 Bevilacqua

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.

dklanac avatar Jun 07 '17 00:06 dklanac

This is still happening, gem version 2.2.1

boxofmattwire avatar Jul 01 '17 16:07 boxofmattwire

I was having the same issue, but it was because of browserify-rails with node_modules.

abimaelmartell avatar Jul 03 '17 22:07 abimaelmartell

@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.

BookOfGreg avatar Oct 30 '17 23:10 BookOfGreg

I've upgraded to 2.3.1. I'm going to give it another shot today.

dklanac avatar Oct 31 '17 12:10 dklanac

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 avatar Nov 01 '17 18:11 dklanac

@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. screen shot 2017-11-01 at 20 54 20

That example is using React-Rails 2.4.0, Sprockets 3.7.1

BookOfGreg avatar Nov 01 '17 20:11 BookOfGreg

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?

dklanac avatar Nov 02 '17 00:11 dklanac

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.

BookOfGreg avatar Nov 02 '17 09:11 BookOfGreg

+1

trivektor avatar Dec 05 '17 10:12 trivektor

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).

fernandobrito avatar Dec 18 '17 15:12 fernandobrito

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.

BookOfGreg avatar Dec 19 '17 09:12 BookOfGreg

👀

ttanimichi avatar Aug 03 '18 11:08 ttanimichi

@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.

BookOfGreg avatar Aug 03 '18 13:08 BookOfGreg

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 avatar Aug 21 '18 18:08 mpantel

@mpantel, Are you still facing this issue? @BookOfGreg We have reopened this issue. Let's wait for @mpantel response.

alkesh26 avatar Oct 31 '22 11:10 alkesh26

Let's close the issue.

alkesh26 avatar Nov 10 '22 18:11 alkesh26