Skip to content

Drop in react version not loaded from asset pipeline #993

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

Closed
hphu3 opened this issue Jun 7, 2019 · 3 comments · Fixed by #994
Closed

Drop in react version not loaded from asset pipeline #993

hphu3 opened this issue Jun 7, 2019 · 3 comments · Fixed by #994

Comments

@hphu3
Copy link
Contributor

hphu3 commented Jun 7, 2019

Steps to reproduce

  1. Add a custom react.js file and/or JSXTransformer.js into your project's asset pipeline.
  2. Observe the custom react version is not loaded.

Expected behavior

According to the docs the custom files should be loaded:
https://github.com/reactjs/react-rails/blob/master/VERSIONS.md#drop-in-version

Actual behavior

Files are not loaded.

System configuration

Sprockets or Webpacker version: Sprockets
React-Rails version: 2.5.0
Rect_UJS version: default
Rails version: 5.1
Ruby version: 2.3.3


Looking at Railtie, it seems like we read the paths from the AssetVariant class https://github.com/reactjs/react-rails/blob/master/lib/react/rails/railtie.rb#L92-L93 but the AssetVariant only looks at files in the gem root: https://github.com/reactjs/react-rails/blob/master/lib/react/rails/asset_variant.rb#L22-L23

It could also be I am misunderstanding the feature since it should work currently if I drop in custom files into the gem's directories.

@BookOfGreg
Copy link
Member

BookOfGreg commented Jun 8, 2019

Bug confirmed.

Reproduction starting from a basic sprockets setup:

ruby -v # ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]
rails -v # Rails 5.2.2.1
rails new test-app
cd test-app
echo "gem 'react-rails'" >> Gemfile
bundle
rails g react:install
rails g react:component hello name:string
rails g controller hello index
echo "<%= react_component 'Hello', {name: 'you'}%>" >> app/views/hello/index.html.erb

rails s and visit http://localhost:3000/hello/index to verify.
Opening up dev console and running React.version shows 16.8.6

For me the easiest place to get other pre-built versiond of react happens to be this gem, so adding in your reproduction:

mkdir -p app/assets/vendor
curl -L https://github.com/reactjs/react-rails/raw/v2.4.7/lib/assets/react-source/production/react.js -o app/assets/vendor/react.js

2.4.7 should be 16.4.2 but...
Opening up dev console and running React.version still shows 16.8.6

@BookOfGreg
Copy link
Member

Aha! However:

rm app/assets/javascripts/server_rendering.js

Opening up dev console and running React.version now shows 16.4.2

Maybe the server_rendering is being badly behaved. If you're not using SSR then Sprockets does let you swap out the react version at will. Still a bug but less severe.

@hphu3
Copy link
Contributor Author

hphu3 commented Jun 14, 2019

Going off of @BookOfGreg's findings, I was able to get it working by dropping in react-server.js alongside the react.js from this repo. Perhaps the documentation can be updated to reflect this.

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

Successfully merging a pull request may close this issue.

2 participants