Skip to content
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

Setting React Variant To Production Has No Effect #715

Closed
1 of 4 tasks
Bevilacqua opened this issue May 15, 2017 · 21 comments
Closed
1 of 4 tasks

Setting React Variant To Production Has No Effect #715

Bevilacqua opened this issue May 15, 2017 · 21 comments

Comments

@Bevilacqua
Copy link

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

@rmosolgo
Copy link
Member

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

@Bevilacqua
Copy link
Author

Sprockets. Should I switch to webpacker?

@rmosolgo
Copy link
Member

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

@Bevilacqua
Copy link
Author

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

@dklanac
Copy link

dklanac commented Jun 7, 2017

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.

@boxofmattwire
Copy link

This is still happening, gem version 2.2.1

@abimaelmartell
Copy link

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

@BookOfGreg
Copy link
Member

@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 BookOfGreg added the bug label Oct 30, 2017
@dklanac
Copy link

dklanac commented Oct 31, 2017

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

@dklanac
Copy link

dklanac commented Nov 1, 2017

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'

@BookOfGreg
Copy link
Member

BookOfGreg commented Nov 1, 2017

@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:
BookOfGreg/react-rails-example-app#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

@dklanac
Copy link

dklanac commented Nov 2, 2017

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?

@BookOfGreg
Copy link
Member

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.

@trivektor
Copy link

trivektor commented Dec 5, 2017

+1

@fernandobrito
Copy link

fernandobrito commented Dec 18, 2017

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

@BookOfGreg
Copy link
Member

BookOfGreg commented Dec 19, 2017

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
Copy link
Member

👀

@BookOfGreg
Copy link
Member

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

@mpantel
Copy link

mpantel commented Aug 21, 2018

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

@BookOfGreg BookOfGreg reopened this Aug 22, 2018
@alkesh26
Copy link
Collaborator

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

@alkesh26
Copy link
Collaborator

Let's close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests