react_on_rails 10.0.2 → 10.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: efb94d1fdde90ef09be7d953e3b139fc5c6b4d9a
4
- data.tar.gz: 45545dd16a35f4ddb94bd6bb9b6e55b9f9a3c639
2
+ SHA256:
3
+ metadata.gz: 9cca491248aecfc5e1611843368b67c30116e92228eebd638ae6d0a9ecc26c79
4
+ data.tar.gz: 54aed2d1114c1cd25ad4fc7efeaf1adce4f352d38e79f07a85594b359383ee0c
5
5
  SHA512:
6
- metadata.gz: ea10bc4fce477f47749c58e63033e71e538ba75fc8b8faa75be1e0fd23910b2082c2b03974e5c352ccbe2ec8cf6faf1e2dbb86b3a975d4992f134812b5866a6c
7
- data.tar.gz: add6268789bca2b97ca812ace89ad98b14721e112768c3da60637b6eeb71541a284b3de27798e8494a75f22fe5773dbcc03c6fc51ad6d3acd193b40144742733
6
+ metadata.gz: ec6eeca7c1606a9deb34daa5675aaf8df3756df75eaa8585d6667e2fd5ef56b546ce6fa2806f532dfad47823a4d681ad83c3767cf8a66e874e80ebbb5bb28cb2
7
+ data.tar.gz: 9133bfcc208013634808483c32805965caf1ca3ee2980d378f1070db60865aefdcf2b99ef09a9aae2797fb388769f3693e6c315eccc1d7d4039aa97a8ff79a6f
@@ -3,7 +3,7 @@
3
3
 
4
4
  AllCops:
5
5
  DisplayCopNames: true
6
- TargetRubyVersion: 2.3
6
+ TargetRubyVersion: 2.1
7
7
 
8
8
  Include:
9
9
  - '**/Rakefile'
@@ -8,6 +8,15 @@ Changes since last non-beta release.
8
8
 
9
9
  *Please add entries here for your pull requests that are not yet released.*
10
10
 
11
+ ### [10.1.0] - 2018-01-23
12
+ #### Added
13
+ - Added 2 cache helpers: ReactOnRails::Utils.bundle_file_name(bundle_name) and ReactOnRails::Utils.server_bundle_file_name
14
+ for easy access to the hashed filenames for use in cache keys by [justin808](https://github.com/justin808).
15
+
16
+ #### Fixed
17
+ - Use redux component in generated redux Hello World example: [PR 1006](https://github.com/shakacode/react_on_rails/pull/1006) by [lewaabahmad](https://github.com/lewaabahmad).
18
+ - Fixed `Utils.bundle_js_file_path` generating the incorrect path for `manifest.json` in webpacker projects: [Issue #1011](https://github.com/shakacode/react_on_rails/issues/1011) by [elstgav](https://github.com/elstgav)
19
+
11
20
  ### [10.0.2] - 2017-11-10
12
21
  #### Fixed
13
22
  - Remove unnecessary dependencies from released NPM package: [PR 968](https://github.com/shakacode/react_on_rails/pull/968) by [tricknotes](https://github.com/tricknotes).
@@ -46,7 +55,7 @@ Updated React on Rails to depend on [rails/webpacker](https://github.com/rails/w
46
55
 
47
56
 
48
57
  #### 9.0 from 8.x. Upgrade Instructions
49
- Moved to [our additional reading documentation](https://github.com/shakacode/react_on_rails/blob/master/docs/additional-reading/upgrading-react-on-rails#from-version-8).
58
+ Moved to [our documentation](docs/basics/upgrading-react-on-rails.md#upgrading-to-version-9).
50
59
 
51
60
  ### [8.0.7] - 2017-08-16
52
61
  #### Fixed
@@ -670,8 +679,9 @@ Best done with Object destructing:
670
679
  ##### Fixed
671
680
  - Fix several generator related issues.
672
681
 
673
- [Unreleased]: https://github.com/shakacode/react_on_rails/compare/10.0.1...master
674
- [10.0.2]: https://github.com/shakacode/react_on_rails/compare/10.0.0...10.0.2
682
+ [Unreleased]: https://github.com/shakacode/react_on_rails/compare/10.1.0...master
683
+ [10.1.0]: https://github.com/shakacode/react_on_rails/compare/10.0.2...10.1.0
684
+ [10.0.2]: https://github.com/shakacode/react_on_rails/compare/10.0.1...10.0.2
675
685
  [10.0.1]: https://github.com/shakacode/react_on_rails/compare/10.0.0...10.0.1
676
686
  [10.0.0]: https://github.com/shakacode/react_on_rails/compare/9.0.3...10.0.0
677
687
  [9.0.3]: https://github.com/shakacode/react_on_rails/compare/9.0.2...9.0.3
@@ -0,0 +1,12 @@
1
+ FROM dylangrafmyre/docker-ci
2
+
3
+ WORKDIR /app/
4
+
5
+ COPY ["/lib/react_on_rails/version.rb", "/app/lib/react_on_rails/"]
6
+ COPY ["Gemfile", "Gemfile.lock", "react_on_rails.gemspec", "rakelib/", "/app/"]
7
+ COPY ["/spec/dummy/Gemfile", "/spec/dummy/Gemfile.lock", "/app/spec/dummy/"]
8
+ RUN bundle install --gemfile=spec/dummy/Gemfile
9
+
10
+ ENV DISPLAY :99
11
+ ENTRYPOINT service xvfd start \
12
+ && rake
data/Gemfile CHANGED
@@ -14,7 +14,7 @@ gem "jbuilder", "~> 2.0"
14
14
  gem "jquery-rails"
15
15
  gem "mini_racer"
16
16
  gem "puma"
17
- gem "rails", "5.1.2"
17
+ gem "rails", "5.1.4"
18
18
  gem "rails_12factor"
19
19
  gem "rubocop", "~> 0.50", require: false
20
20
  gem "ruby-lint", require: false
@@ -5,9 +5,10 @@
5
5
  ## Commercial Products Live
6
6
  * **[Friends and Guests](https://www.friendsandguests.com/)**, the signature product of [ShakaCode](http://www.shakacode.com), which is a "Network Connecting Hosts and Guests".
7
7
  * **[KissKissBankBank](https://www.kisskissbankbank.com/)**, large French crowdfunding platform.
8
- * **[Nootrobox](https://nootrobox.com)**: Web ecommerce site for "biohacking" products.
8
+ * **[HVMN](https://hvmn.com)**: Web ecommerce site for "biohacking" products.
9
9
  * **[GuavaPass](https://guavapass.com/)**: Coaching client of [ShakaCode](http://www.shakacode.com) and React on Rails fan!
10
10
  * **[Pivotal Tracker](http://www.pivotaltracker.com/)**: The first (and most-loved) agile project management tool built on Rails. React on Rails has greatly simplified integration and workflow for our React components in Rails!
11
+ * **[Estately](https://www.estately.com)**: Home search.
11
12
  * **[Blink Inc](https://www.blinkinc.com)**: Website and more built by [ShakaCode](http://www.shakacode.com).
12
13
  * **[Madrone Analytics](http://madroneco.com/)**: The original client of [ShakaCode](http://www.shakacode.com) that led to the development of React on Rails, as described in [Fast Rich Client Rails Development With Webpack and the ES6 Transpiler](http://www.railsonmaui.com/blog/2014/10/03/integrating-webpack-and-the-es6-transpiler-into-an-existing-rails-project/).
13
14
  * **[Deliveroo](https://deliveroo.co.uk/)**: The leading food delivery site in Europe has gone live with React on Rails, with multi-lingual JavaScript support!
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  *If this projects helps you, please give us a star!*
4
4
 
5
- [ShakaCode is hiring team members](http://www.shakacode.com/about/#work-with-us) for our own app, [Friends and Guests](https://www.friendsandguests.com).
5
+ [The ShakaCode team has availability to help your project](http://www.shakacode.com/work). If your team might need my help, please [email me](mailto:justin@shakacode.com) for a free half-hour project consultation, on anything from React on Rails to any aspect of web or mobile application development for both consumer and enterprise products.
6
6
 
7
7
  # React on Rails v10 is based on Webpacker 3.0!
8
8
 
@@ -23,14 +23,14 @@ Given that Webpacker already provides React integration, why would you add React
23
23
 
24
24
  ----
25
25
 
26
- ## Steps to a New App with rails/webpacker v3 plus React on Rails v9:
26
+ ## Steps to a New App with rails/webpacker v3 plus latest React on Rails:
27
27
  First be sure to run `rails -v` and check that you are using Rails 5.1.3 or above. If you are using an older version of Rails, you'll need to install webpacker with React per the instructions [here](https://github.com/rails/webpacker).
28
28
 
29
29
  ### Basic installation for a new Rails App
30
30
  *See below for steps on an existing Rails app*
31
31
 
32
32
  1. New Rails app: `rails new my-app --webpack=react`. `cd` into the directory.
33
- 2. Add gem version: `gem 'react_on_rails', '~> 9.0.1'`
33
+ 2. Add gem version: `gem 'react_on_rails', '10.0.2' # prefer exact gem version to match npm version`
34
34
  3. Run the generator: `rails generate react_on_rails:install`
35
35
  4. Start the app: `rails s`
36
36
  5. Visit http://localhost:3000/hello_world
@@ -59,7 +59,7 @@ Thank you for considering using [React on Rails](https://github.com/shakacode/re
59
59
 
60
60
  We at [ShakaCode](http://www.shakacode.com) are a small, boutique, remote-first application development company. We fund this project by:
61
61
 
62
- * Providing priority support and training for anything related to React + Webpack + Rails in our [Coaching Program](http://www.shakacode.com/work/shakacode-coaching-plan.pdf).
62
+ * Providing priority support and training for anything related to React + Webpack + Rails in our [Pro Support program](http://www.shakacode.com/work/shakacode-pro-support.pdf).
63
63
  * Building custom web and mobile (React Native) applications. We typically work with a technical founder or CTO and instantly provide a full development team including designers.
64
64
  * Migrating **Angular** + Rails to React + Rails. You can see an example of React on Rails and our work converting Angular to React on Rails at [egghead.io](https://egghead.io/browse/frameworks).
65
65
  * Augmenting your team to get your product completed more efficiently and quickly.
@@ -68,7 +68,7 @@ My article "[Why Hire ShakaCode?](https://blog.shakacode.com/can-shakacode-help-
68
68
 
69
69
  If any of this resonates with you, please email me, [justin@shakacode.com](mailto:justin@shakacode.com). I offer a free half-hour project consultation, on anything from React on Rails to any aspect of web or mobile application development for both consumer and enterprise products.
70
70
 
71
- We are **[currently looking to hire](http://www.shakacode.com/about/#work-with-us)** like-minded developers that wish to work on our projects, including [Friends and Guests](https://www.friendsandguests.com).
71
+ We are **[currently looking to hire](http://www.shakacode.com/about/#work-with-us)** like-minded developers that wish to work on our projects, including [Hawaii Chee](https://www.hawaiichee.com).
72
72
 
73
73
  I appreciate your attention and sharing of these offerings with anybody that we can help. Your support allows me to bring you and your team [front-end happiness in the Rails world](https://www.youtube.com/watch?v=SGkTvKRPYrk).
74
74
 
@@ -138,11 +138,15 @@ React on Rails integrates Facebook's [React](https://github.com/facebook/react)
138
138
 
139
139
  + [Features](#features)
140
140
  + [Why Webpack?](#why-webpack)
141
+ + [rails/webpacker or custom setup for Webpack?](#webpack-configuration-custom-setup-for-webpack-or-railswebpacker)
141
142
  + [Getting Started with an existing Rails app](#getting-started-with-an-existing-rails-app)
142
143
  - [Installation Overview](#installation-overview)
143
144
  - [Initializer Configuration: config/initializers/react_on_rails.rb](#initializer-configuration)
144
145
  - [Including your React Component in your Rails Views](#including-your-react-component-in-your-rails-views)
145
146
  - [I18n](#i18n)
147
+ - [Convert rails-5 API only app to rails app](#convert-rails-5-api-only-app-to-rails-app)
148
+ - [NPM](#npm)
149
+ - [Webpacker Configuration](#webpacker-configuration)
146
150
  + [How it Works](#how-it-works)
147
151
  - [Client-Side Rendering vs. Server-Side Rendering](#client-side-rendering-vs-server-side-rendering)
148
152
  - [Building the Bundles](#building-the-bundles)
@@ -179,6 +183,38 @@ This usage of webpack fits neatly and simply into existing Rails apps. You can i
179
183
  Compare this to some alternative approaches for SPAs (Single Page Apps) that utilize Webpack and Rails. They will use a separate node server to distribute web pages, JavaScript assets, CSS, etc., and will still use Rails as an API server. A good example of this is our ShakaCode team member Alex's article [
180
184
  Universal React with Rails: Part I](https://medium.com/@alexfedoseev/isomorphic-react-with-rails-part-i-440754e82a59).
181
185
 
186
+ ## Webpack Configuration: custom setup for Webpack or rails/webpacker?
187
+
188
+ Version 9 of React on Rails added support for the rails/webpacker view helpers so that Webpack produced assets would no longer pass through the Rails asset pipeline. As part of this change, React on Rails added a configuration option to support customization of the node_modules directory. This allowed React on Rails to support the rails/webpacker configuration of the Webpack configuration.
189
+
190
+ A key decision in your use React on Rails is whether you go with the rails/webpacker default setup or the traditional React on Rails setup of putting all your client side files under the `/client` directory. While there are technically 2 independent choices involved, the directory structure and the mechanism of Webpack configuration, for simplicity sake we'll assume that these choices go together.
191
+
192
+ ### Traditional React on Rails using the /client directory
193
+
194
+ Until version 9, all React on Rails apps used the `/client` directory for configuring React on Rails in terms of the configuration of Webpack and location of your JavaScript and Webpack files, including the node_modules directory. Version 9 changed the default to `/` for the `node_modules` location using this value in `config/initializers/react_on_rails.rb`: `config.node_modules_location`.
195
+
196
+ The [ShakaCode Team](http://www.shakacode.com) _recommends_ this approach for projects beyond the simplest cases as it provides the greatest transparency in your webpack and overall client-side setup. The *big advantage* to this is that almost everything within the `/client` directory will apply if you wish to convert your client-side code to a pure Single Page Application that runs without Rails. This allows you to google for how to do something with Webpack configuration and what applies to a non-Rails app will apply just as well to a React on Rails app.
197
+
198
+ The two best examples of this patten are the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) and the integration test example in [spec/dummy](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy).
199
+
200
+ In this case, you don't need to understand the nuances of customization of your Wepback config via the [Webpacker mechanism](https://github.com/rails/webpacker/blob/master/docs/webpack.md).
201
+
202
+
203
+ ### rails/webpacker Setup
204
+
205
+ Typical rails/webpacker apps have a standard directory structure as documented [here](https://github.com/rails/webpacker/blob/master/docs/folder-structure.md). If you follow the steps in the the [basic tutorial](https://github.com/shakacode/react_on_rails/blob/master/docs/tutorial.md), you will see this pattern in action. In order to customize the Webpack configuration, you need to consult with the [rails/webpacker Webpack configuration](https://github.com/rails/webpacker/blob/master/docs/webpack.md).
206
+
207
+ Version 9 made this the default for generated apps for 2 reasons:
208
+
209
+ 1. It's less code to generate and thus less to explain.
210
+ 2. `rails/webpacker` might be viewed as a convention in the Rails community.
211
+
212
+ The *advantage* of this is that there is very little code needed to get started and you don't need to understand really anything about Webpack customization. The *big disadvantage* to this is that you will need to learn the ins and outs of the [rails/webpacker way to customize Webpack]([Webpacker mechanism](https://github.com/rails/webpacker/blob/master/docs/webpack.md)) (not the plain [Webpack way](https://webpack.js.org/)) if you wish to beyond the basic setup, and this sort of knowledge is not going to be particularly applicable if you eventually want to convert your client-side app to a pure Single Page Application that runs without rails.
213
+
214
+ Overall, consider carefully if you prefer the `rails/webpacker` directory structure and Webpack configuration, over the placement of all client side files within the `/client` directory along with conventional Webpack configuration.
215
+
216
+ See [Issue 982: Tutorial Generating Correct Project Structure?](https://github.com/shakacode/react_on_rails/issues/982) to discuss this issue.
217
+
182
218
  ## Upgrade
183
219
 
184
220
  To upgrade existing apps to React on Rails 8 see the [Installation Overview](docs/basics/installation-overview.md)
@@ -187,6 +223,7 @@ To upgrade existing apps to React on Rails 8 see the [Installation Overview](doc
187
223
 
188
224
  **For more detailed instructions on a fresh Rails app**, see the [React on Rails Basic Tutorial](docs/tutorial.md).
189
225
 
226
+ **If you have rails-5 API only project**, Then [convert rails-5 API only app to rails app](#convert-rails-5-api-only-app-to-rails-app) before [getting started](#getting-started-with-an-existing-rails-app).
190
227
  1. Add the following to your Gemfile and `bundle install`. We recommend fixing the version of React on Rails, as you will need to keep the exact version in sync with the version in your `client/package.json` file.
191
228
 
192
229
  ```ruby
@@ -276,7 +313,28 @@ React on Rails provides an option for automatic conversions of Rails `*.yml` loc
276
313
 
277
314
  See the [How to add I18n](docs/basics/i18n.md) for a summary of adding I18n.
278
315
 
279
- ## NPM
316
+ ### Convert rails-5 API only app to rails app
317
+
318
+ 1. Go to the directory where you created your app
319
+
320
+ ```
321
+ rails new your-current-app-name
322
+ ```
323
+
324
+ Rails will start creating the app and will skip the files you have already created. If there is some conflict then it will stop and you need to resolve it manually. be careful at this step as it might replace you current code in conflicted files.
325
+
326
+ 2. Resolve conflicts
327
+
328
+ ```
329
+ 1. Press "d" to see the difference
330
+ 2. If it is only adding lines then press "y" to continue
331
+ 3. If it is removeing some of your code then press "n" and add all additions manually
332
+ ```
333
+
334
+ 3. Run `bundle install` and follow [Getting started](#getting-started-with-an-existing-rails-app)
335
+
336
+
337
+ ### NPM
280
338
  All JavaScript in React On Rails is loaded from npm: [react-on-rails](https://www.npmjs.com/package/react-on-rails). To manually install this (you did not use the generator), assuming you have a standard configuration, run this command (assuming you are in the directory where you have your `node_modules`):
281
339
 
282
340
  ```bash
@@ -285,7 +343,7 @@ yarn add react-on-rails
285
343
 
286
344
  That will install the latest version and update your package.json.
287
345
 
288
- ## Webpacker Configuration
346
+ ### Webpacker Configuration
289
347
 
290
348
  React on Rails users should set configuration value `compile` to false, as React on Rails handles compilation for test and production environments.
291
349
 
@@ -621,8 +679,11 @@ If you are using [jquery-ujs](https://github.com/rails/jquery-ujs) for AJAX call
621
679
  1. Examples in [spec/dummy/app/views/react_router](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/app/views/react_router) and follow to the JavaScript code in the [spec/dummy/client/app/startup/ServerRouterApp.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/ServerRouterApp.jsx).
622
680
  1. [Code Splitting docs](./docs/additional-reading/code-splitting.md) for information about how to set up code splitting for server rendered routes.
623
681
 
682
+ ## Caching and Performance
683
+ Consider fragment and http caching of pages that contain React on Rails components. See [Caching and Performance](./docs/additional-reading/caching-and-performance.md) for more details.
684
+
624
685
  ## Deployment
625
- * Version 6.0 puts the necessary precompile steps automatically in the rake precompile step. You can, however, disable this by setting certain values to nil in the [config/initializers/react_on_rails.rb](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/config/initializers/react_on_rails.rb).
686
+ * React on Rails puts the necessary precompile steps automatically in the rake precompile step. You can, however, disable this by setting certain values to nil in the [config/initializers/react_on_rails.rb](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/config/initializers/react_on_rails.rb).
626
687
  * `config.symlink_non_digested_assets_regex`: Set to nil to turn off the setup of non-js assets.
627
688
  * `build_production_command`: Set to nil to turn off the precompilation of the js assets.
628
689
  * See the [Heroku Deployment](./docs/additional-reading/heroku-deployment.md) doc for specifics regarding Heroku. The information here should apply to other deployments.
@@ -666,6 +727,7 @@ If you want to use a node server for server rendering, [get in touch](mailto:jus
666
727
  + [Hot Reloading of Assets For Rails Development](./docs/additional-reading/hot-reloading-rails-development.md)
667
728
  + [Heroku Deployment](./docs/additional-reading/heroku-deployment.md)
668
729
  + [Updating Dependencies](./docs/additional-reading/updating-dependencies.md)
730
+ + [Caching and Performance](./docs/additional-reading/caching-and-performance.md)
669
731
 
670
732
  + **API**
671
733
  + [JavaScript API](./docs/api/javascript-api.md)
@@ -747,7 +809,7 @@ Thank you for considering using [React on Rails](https://github.com/shakacode/re
747
809
 
748
810
  We at [ShakaCode](http://www.shakacode.com) are a small, boutique, remote-first application development company. We fund this project by:
749
811
 
750
- * Providing priority support and training for anything related to React + Webpack + Rails in our [Coaching Program](http://www.shakacode.com/work/shakacode-coaching-plan.pdf).
812
+ * Providing priority support and training for anything related to React + Webpack + Rails in our [Pro Support program](http://www.shakacode.com/work/shakacode-pro-support.pdf).
751
813
  * Building custom web and mobile (React Native) applications. We typically work with a technical founder or CTO and instantly provide a full development team including designers.
752
814
  * Migrating **Angular** + Rails to React + Rails. You can see an example of React on Rails and our work converting Angular to React on Rails at [egghead.io](https://egghead.io/browse/frameworks).
753
815
  * Augmenting your team to get your product completed more efficiently and quickly.
@@ -756,7 +818,7 @@ My article "[Why Hire ShakaCode?](https://blog.shakacode.com/can-shakacode-help-
756
818
 
757
819
  If any of this resonates with you, please email me, [justin@shakacode.com](mailto:justin@shakacode.com). I offer a free half-hour project consultation, on anything from React on Rails to any aspect of web or mobile application development for both consumer and enterprise products.
758
820
 
759
- We are **[currently looking to hire](http://www.shakacode.com/about/#work-with-us)** like-minded developers that wish to work on our projects, including [Friends and Guests](https://www.friendsandguests.com).
821
+ We are **[currently looking to hire](http://www.shakacode.com/about/#work-with-us)** like-minded developers that wish to work on our projects, including [Hawaii Chee](https://www.hawaiichee.com).
760
822
 
761
823
  I appreciate your attention and sharing of these offerings with anybody that we can help. Your support allows me to bring you and your team [front-end happiness in the Rails world](https://www.youtube.com/watch?v=SGkTvKRPYrk).
762
824
 
@@ -13,7 +13,7 @@ require "react_on_rails/json_output"
13
13
  module ReactOnRailsHelper
14
14
  include ReactOnRails::Utils::Required
15
15
 
16
- COMPONENT_HTML_KEY = "componentHtml"
16
+ COMPONENT_HTML_KEY = "componentHtml".freeze
17
17
 
18
18
  # The env_javascript_include_tag and env_stylesheet_link_tag support the usage of a webpack
19
19
  # dev server for providing the JS and CSS assets during development mode. See
@@ -178,9 +178,7 @@ module ReactOnRailsHelper
178
178
  # that contains a data props.
179
179
  def redux_store_hydration_data
180
180
  return if @registered_stores_defer_render.blank?
181
- # rubocop:disable Performance/UnfreezeString
182
181
  @registered_stores_defer_render.reduce("".dup) do |accum, redux_store_data|
183
- # rubocop:enable Performance/UnfreezeString
184
182
  accum << render_redux_store_data(redux_store_data)
185
183
  end.html_safe
186
184
  end
@@ -447,15 +445,12 @@ module ReactOnRailsHelper
447
445
 
448
446
  def initialize_redux_stores
449
447
  return "" unless @registered_stores.present? || @registered_stores_defer_render.present?
450
- declarations = "var reduxProps, store, storeGenerator;\n".dup # rubocop:disable Performance/UnfreezeString
451
-
448
+ declarations = "var reduxProps, store, storeGenerator;\n".dup
452
449
  all_stores = (@registered_stores || []) + (@registered_stores_defer_render || [])
453
450
 
454
- # rubocop:disable Performance/UnfreezeString
455
451
  result = <<-JS.dup
456
452
  ReactOnRails.clearHydratedStores();
457
453
  JS
458
- # rubocop:enable Performance/UnfreezeString
459
454
 
460
455
  result << all_stores.each_with_object(declarations) do |redux_store_data, memo|
461
456
  store_name = redux_store_data[:store_name]
@@ -516,6 +511,7 @@ module ReactOnRailsHelper
516
511
 
517
512
  @rails_context.merge(serverSide: server_side)
518
513
  end
514
+ # rubocop:enable Metrics/AbcSize
519
515
 
520
516
  def replay_console_option(val)
521
517
  val.nil? ? ReactOnRails.configuration.replay_console : val
@@ -539,3 +535,4 @@ module ReactOnRailsHelper
539
535
  controller.is_a?(ActionMailer::Base)
540
536
  end
541
537
  end
538
+ # rubocop:enable Metrics/ModuleLength
@@ -0,0 +1,11 @@
1
+ lint:
2
+ image: dylangrafmyre/docker-lint:latest
3
+ working_dir: /app/
4
+ volumes:
5
+ - '.:/app/'
6
+ tests:
7
+ build: .
8
+ dockerfile: Dockerfile_tests
9
+ working_dir: /app/
10
+ volumes:
11
+ - '.:/app/'
@@ -0,0 +1,31 @@
1
+ # Caching and Performance
2
+
3
+
4
+ ## Caching
5
+
6
+ ### Fragment Caching
7
+
8
+ If you wish to do fragment caching that includes React on Rails rendered components, be sure to
9
+ include the bundle name of your server rendering bundle in your cache key. This is analogous to
10
+ how Rails puts an MD5 hash of your views in the cache key so that if the views change, then your
11
+ cache is busted. In the case of React code, if your React code changes, then your bundle name will
12
+ change due to the typical inclusion of a hash in the name.
13
+
14
+ Call this method to get the server bundle file name:
15
+
16
+ ```ruby
17
+ # Returns the hashed file name of the server bundle when using webpacker.
18
+ # Nececessary fragment-caching keys.
19
+ ReactOnRails::Utils.server_bundle_file_name
20
+ ```
21
+
22
+ ### HTTP Caching
23
+
24
+ When creating a HTTP cache, you want the cache key to include your client bundle files.
25
+
26
+ Call this method to get the client bundle file name. Note, you have to pass which bundle name.
27
+
28
+ ```ruby
29
+ # Returns the hashed file name when using webpacker. Useful for creating cache keys.
30
+ ReactOnRails::Utils..bundle_file_name(bundle_name)
31
+ ```
@@ -1,3 +1,8 @@
1
- PENDING:
1
+ # View Helpers
2
+ See the [app/helpers/react_on_rails_helper.rb](../../app/helpers/react_on_rails_helper.rb) source.
2
3
 
3
- Should we document the view helpers here concisely?
4
+ # Controller Helpers
5
+ See the [lib/react_on_rails/controller.rb](../../lib/react_on_rails/controller.rb) source.
6
+
7
+ # Utility Methods
8
+ See the [lib/react_on_rails/utils.rb](../../lib/react_on_rails/utils.rb) source.
@@ -1,9 +1,6 @@
1
1
  # React on Rails Basic Tutorial
2
2
 
3
- * NOTE: Please be sure to use the BETA or RC versions of React on Rails until 9.0 is released.*
4
-
5
-
6
- This tutorial setups up a new Rails app with **React on Rails**, demonstrating Rails + React + Redux + Server Rendering. It is updated to 9.0.0.
3
+ This tutorial guides you through setting up a new or existing Rails app with **React on Rails**, demonstrating Rails + React + Redux + Server Rendering. It is updated to 10.0.2.
7
4
 
8
5
  After finishing this tutorial you will get an application that can do the following (live on Heroku):
9
6
 
@@ -39,7 +36,7 @@ gem install rails # download and install latest stable Rails
39
36
  gem install foreman # download and install Foreman
40
37
  ```
41
38
 
42
- Then we need to create a fresh Rails application with webpacker react support as following. Be sure that
39
+ Then we need to create a fresh Rails application with webpacker react support as following.
43
40
 
44
41
  First be sure to run `rails -v` and check you are using Rails 5.1.3 or above. If you are using an older version of Rails, you'll need to install webpacker with react per the instructions [here](https://github.com/rails/webpacker).
45
42
 
@@ -52,23 +49,22 @@ rails new test-react-on-rails --webpack=react
52
49
  cd test-react-on-rails
53
50
  ```
54
51
 
55
- Note: you can do the following two commands in an existing Rails app or pre Rails 5.1.3:
52
+ Note: if you are installing React On Rails in an existing app or an app that uses Rails pre 5.1.3, you will need to run these two commands as well:
56
53
 
57
54
  ```
58
55
  bundle exec rails webpacker:install
59
56
  bundle exec rails webpacker:install:react
60
57
  ```
61
58
 
62
-
63
-
64
59
  Add the **React On Rails** gem to your Gemfile:
65
60
 
66
61
  ```
67
- gem 'react_on_rails', '9.0.0' # use latest gem version, prefer exact version
62
+ gem 'react_on_rails', '10.0.2' # prefer exact gem version to match npm version
68
63
  ```
69
64
 
65
+ Note: Latest released React On Rails version is considered stable. Please use the latest version to ensure you get all the security patches and the best support.
70
66
 
71
- Then run `bundle` and commit the git repository (or `rails generate` will not work properly)
67
+ Run `bundle` and commit the git repository (or `rails generate` will not work properly)
72
68
 
73
69
 
74
70
  ```
@@ -80,7 +76,7 @@ git add -A
80
76
  git commit -m "Initial commit"
81
77
  ```
82
78
 
83
- Install React on Rails: `rails generator react_on_rails:install` or `rails generate react_on_rails:install --redux`. You need to first git commit your files before running the generator, or else it will generate an error.
79
+ Install React on Rails: `rails generate react_on_rails:install` or `rails generate react_on_rails:install --redux`. You need to first git commit your files before running the generator, or else it will generate an error.
84
80
 
85
81
  ```
86
82
  rails generate react_on_rails:install
@@ -55,6 +55,8 @@ module ReactOnRails
55
55
  if File.exist?(spec_helper)
56
56
  add_configure_rspec_to_compile_assets(spec_helper)
57
57
  else
58
+ # rubocop:disable Lint/UnneededDisable
59
+ # rubocop:disable Layout/EmptyLinesAroundArguments
58
60
  GeneratorMessages.add_info(
59
61
  <<-MSG.strip_heredoc
60
62
 
@@ -67,6 +69,8 @@ module ReactOnRails
67
69
  ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
68
70
  MSG
69
71
  )
72
+ # rubocop:enable Layout/EmptyLinesAroundArguments
73
+ # rubocop:enable Lint/UnneededDisable
70
74
  end
71
75
  end
72
76
  end
@@ -14,7 +14,7 @@ module ReactOnRails
14
14
  end
15
15
 
16
16
  def copy_base_files
17
- base_js_path = "base/base"
17
+ base_js_path = "redux/base"
18
18
  base_files = %w[app/javascript/bundles/HelloWorld/components/HelloWorld.jsx]
19
19
  base_files.each { |file| copy_file("#{base_js_path}/#{file}", file) }
20
20
  end
@@ -13,7 +13,7 @@ export default class HelloWorld extends React.Component {
13
13
  super(props);
14
14
 
15
15
  // How to set initial state in ES6 class syntax
16
- // https://facebook.github.io/react/docs/reusable-components.html#es6-classes
16
+ // https://reactjs.org/docs/state-and-lifecycle.html#adding-local-state-to-a-class
17
17
  this.state = { name: this.props.name };
18
18
  }
19
19
 
@@ -102,8 +102,8 @@ module ReactOnRails
102
102
  next unless File.lstat(filename).symlink?
103
103
  begin
104
104
  target = File.readlink(filename)
105
- rescue # rubocop:disable Lint/RescueWithoutErrorClass
106
- puts "React on Rails: Warning: your platform doesn't support File::readlink method." /
105
+ rescue StandardError
106
+ puts "React on Rails: Warning: your platform doesn't support File::readlink method." \
107
107
  "Skipping broken link check."
108
108
  break
109
109
  end
@@ -139,7 +139,7 @@ module ReactOnRails
139
139
  # pointing to. We can't use File.exist?, as that would check the file pointed at by the symlink.
140
140
  File.lstat(path)
141
141
  true
142
- rescue # rubocop:disable Lint/RescueWithoutErrorClass
142
+ rescue StandardError
143
143
  false
144
144
  end
145
145
  end
@@ -62,9 +62,8 @@ module ReactOnRails
62
62
  return unless @configuration.webpack_generated_files.empty?
63
63
 
64
64
  files = ["hello-world-bundle.js"]
65
- if @configuration.server_bundle_js_file.present?
66
- files << @configuration.server_bundle_js_file
67
- end
65
+ files << @configuration.server_bundle_js_file if @configuration.server_bundle_js_file.present?
66
+
68
67
  @configuration.webpack_generated_files = files
69
68
  end
70
69
 
@@ -85,7 +84,6 @@ module ReactOnRails
85
84
  @configuration ||= Configuration.new(
86
85
  node_modules_location: nil,
87
86
  generated_assets_dirs: nil,
88
-
89
87
  # generated_assets_dirs is deprecated
90
88
  generated_assets_dir: "",
91
89
  server_bundle_js_file: "",
@@ -98,7 +96,6 @@ module ReactOnRails
98
96
  server_renderer_pool_size: 1,
99
97
  server_renderer_timeout: 20,
100
98
  skip_display_none: nil,
101
-
102
99
  # skip_display_none is deprecated
103
100
  webpack_generated_files: %w[manifest.json],
104
101
  rendering_extension: nil,
@@ -6,7 +6,7 @@ module ReactOnRails
6
6
  # err might be nil if JS caught the error
7
7
  def initialize(component_name: nil, err: nil, props: nil,
8
8
  js_code: nil, console_messages: nil)
9
- message = "ERROR in SERVER PRERENDERING\n".dup # rubocop:disable Performance/UnfreezeString
9
+ message = "ERROR in SERVER PRERENDERING\n".dup
10
10
  if err
11
11
  # rubocop:disable Layout/IndentHeredoc
12
12
  message << <<-MSG
@@ -22,6 +22,7 @@ module ReactOnRails
22
22
  def method_missing(sym, *args, &block)
23
23
  pool.send sym, *args, &block
24
24
  end
25
+ # rubocop:enable Style/MethodMissing
25
26
  end
26
27
  end
27
28
  end
@@ -98,7 +98,7 @@ module ReactOnRails
98
98
  # bundle_js_code = File.read(server_js_file)
99
99
  begin
100
100
  bundle_js_code = open(server_js_file, &:read)
101
- rescue => e # rubocop:disable Lint/RescueWithoutErrorClass
101
+ rescue StandardError
102
102
  msg = "You specified server rendering JS file: #{server_js_file}, but it cannot be "\
103
103
  "read. You may set the server_bundle_js_file in your configuration to be \"\" to "\
104
104
  "avoid this warning.\nError is: #{e}"
@@ -115,7 +115,7 @@ module ReactOnRails
115
115
  begin
116
116
  trace_messsage(base_js_code, file_name)
117
117
  ExecJS.compile(base_js_code)
118
- rescue => e # rubocop:disable Lint/RescueWithoutErrorClass
118
+ rescue StandardError
119
119
  msg = "ERROR when compiling base_js_code! "\
120
120
  "See file #{file_name} to "\
121
121
  "correlate line numbers of error. Error is\n\n#{e.message}"\
@@ -58,9 +58,7 @@ module ReactOnRails
58
58
  @js_context_pool.with do |js_context|
59
59
  js_context.send(js_code + eof_symbol, 0)
60
60
  result = ""
61
- while result[-eof_symbol.length..-1] != eof_symbol
62
- result += js_context.recv(max_int)
63
- end
61
+ result[-eof_symbol.length..-1] != eof_symbol while result += js_context.recv(max_int)
64
62
  result[0..-eof_symbol.length]
65
63
  end
66
64
  end
@@ -8,6 +8,33 @@ require "active_support/core_ext/string"
8
8
 
9
9
  module ReactOnRails
10
10
  module Utils
11
+ ###########################################################
12
+ # PUBLIC API
13
+ ###########################################################
14
+
15
+ # Returns the hashed file name when using webpacker. Useful for creating cache keys.
16
+ def self.bundle_file_name(bundle_name)
17
+ raise "Only call bundle_file_name if using webpacker" unless using_webpacker?
18
+ full_path = bundle_js_file_path_from_webpacker(bundle_name)
19
+ pathname = Pathname.new(full_path)
20
+ pathname.basename.to_s
21
+ end
22
+
23
+ # Returns the hashed file name of the server bundle when using webpacker.
24
+ # Nececessary fragment-caching keys.
25
+ def self.server_bundle_file_name
26
+ return @server_bundle_hash if @server_bundle_hash && !Rails.env.development?
27
+
28
+ @server_bundle_hash = begin
29
+ server_bundle_name = ReactOnRails.configuration.server_bundle_js_file
30
+ bundle_file_name(server_bundle_name)
31
+ end
32
+ end
33
+
34
+ ###########################################################
35
+ # PRIVATE API -- Subject to change
36
+ ###########################################################
37
+
11
38
  # https://forum.shakacode.com/t/yak-of-the-week-ruby-2-4-pathname-empty-changed-to-look-at-file-size/901
12
39
  # return object if truthy, else return nil
13
40
  def self.truthy_presence(obj)
@@ -85,8 +112,7 @@ exitstatus: #{status.exitstatus}#{stdout_msg}#{stderr_msg}
85
112
  end
86
113
 
87
114
  def self.bundle_js_file_path(bundle_name)
88
- if using_webpacker?
89
- return bundle_name if bundle_name == "manifest.json"
115
+ if using_webpacker? && bundle_name != "manifest.json"
90
116
  bundle_js_file_path_from_webpacker(bundle_name)
91
117
  else
92
118
  # Default to the non-hashed name in the specified output directory, which, for legacy
@@ -102,9 +128,7 @@ exitstatus: #{status.exitstatus}#{stdout_msg}#{stderr_msg}
102
128
  def self.rails_version_less_than(version)
103
129
  @rails_version_less_than ||= {}
104
130
 
105
- if @rails_version_less_than.key?(version)
106
- return @rails_version_less_than[version]
107
- end
131
+ return @rails_version_less_than[version] if @rails_version_less_than.key?(version)
108
132
 
109
133
  @rails_version_less_than[version] = begin
110
134
  Gem::Version.new(Rails.version) < Gem::Version.new(version)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReactOnRails
4
- VERSION = "10.0.2"
4
+ VERSION = "10.1.0".freeze
5
5
  end
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-on-rails",
3
- "version": "10.0.2",
3
+ "version": "10.1.0",
4
4
  "description": "react-on-rails JavaScript for react_on_rails Ruby gem",
5
5
  "main": "node_package/lib/ReactOnRails.js",
6
6
  "directories": {
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "task_helpers"
4
- include ReactOnRails::TaskHelpers
5
4
 
6
5
  namespace :dummy_apps do
6
+ include ReactOnRails::TaskHelpers
7
+
7
8
  task :yarn_install do
8
9
  yarn_install_cmd = "yarn install --mutex network"
9
10
  sh_in_dir(dummy_app_dir, yarn_install_cmd)
@@ -8,8 +8,9 @@
8
8
  require "yaml"
9
9
  require_relative "example_type"
10
10
  require_relative "task_helpers"
11
- include ReactOnRails::TaskHelpers
11
+
12
12
  namespace :examples do # rubocop:disable Metrics/BlockLength
13
+ include ReactOnRails::TaskHelpers
13
14
  # Loads data from examples_config.yml and instantiates corresponding ExampleType objects
14
15
  examples_config_file = File.expand_path("../examples_config.yml", __FILE__)
15
16
  examples_config = symbolize_keys(YAML.safe_load(File.read(examples_config_file)))
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "task_helpers"
4
- include ReactOnRails::TaskHelpers
5
4
 
6
- namespace :lint do
5
+ namespace :lint do # rubocop:disable Metrics/BlockLength
6
+ include ReactOnRails::TaskHelpers
7
+
7
8
  desc "Run Rubocop as shell"
8
9
  task :rubocop do
9
10
  sh_in_dir(gem_root, "bundle exec rubocop .")
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "task_helpers"
4
- include ReactOnRails::TaskHelpers
5
4
 
6
5
  namespace :node_package do
6
+ include ReactOnRails::TaskHelpers
7
+
7
8
  task :build do
8
9
  puts "Building Node Package and running 'yarn link'"
9
10
  sh "yarn run build && yarn link"
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "task_helpers"
4
- include ReactOnRails::TaskHelpers
5
4
  require_relative File.join(gem_root, "lib", "react_on_rails", "version_syntax_converter")
6
5
  require_relative File.join(gem_root, "lib", "react_on_rails", "git_utils")
7
6
  require_relative File.join(gem_root, "lib", "react_on_rails", "utils")
8
7
 
8
+ # rubocop:disable Lint/UnneededDisable
9
+ # rubocop:disable Layout/EmptyLinesAroundArguments
9
10
  desc("Releases both the gem and node package using the given version.
10
11
 
11
12
  IMPORTANT: the gem version must be in valid rubygem format (no dashes).
@@ -21,9 +22,13 @@ which are installed via `bundle install` and `yarn`
21
22
  2nd argument: Perform a dry run by passing 'true' as a second argument.
22
23
 
23
24
  Example: `rake release[2.1.0,false]`")
25
+ # rubocop:enable Layout/EmptyLinesAroundArguments
26
+ # rubocop:enable Lint/UnneededDisable
24
27
 
25
28
  # rubocop:disable Metrics/BlockLength
26
29
  task :release, %i[gem_version dry_run tools_install] do |_t, args|
30
+ include ReactOnRails::TaskHelpers
31
+
27
32
  class MessageHandler
28
33
  def add_error(error)
29
34
  raise error
@@ -60,9 +65,7 @@ task :release, %i[gem_version dry_run tools_install] do |_t, args|
60
65
  sh_in_dir(gem_root, "git add .")
61
66
 
62
67
  # Will bump the yarn version, commit, tag the commit, push to repo, and release on yarn
63
- # rubocop:disable Performance/UnfreezeString
64
68
  release_it_command = "$(yarn bin)/release-it --non-interactive --npm.publish".dup
65
- # rubocop:enable Performance/UnfreezeString
66
69
  release_it_command << " --dry-run --verbose" if is_dry_run
67
70
  release_it_command << " #{npm_version}" unless npm_version.strip.empty?
68
71
  sh_in_dir(gem_root, release_it_command)
@@ -77,3 +80,4 @@ task :release, %i[gem_version dry_run tools_install] do |_t, args|
77
80
  sh_in_dir(gem_root, "git push")
78
81
  end
79
82
  end
83
+ # rubocop:enable Metrics/BlockLength
@@ -7,10 +7,10 @@ require "pathname"
7
7
  require_relative "task_helpers"
8
8
  require_relative "example_type"
9
9
 
10
- include ReactOnRails::TaskHelpers
11
-
12
10
  # rubocop:disable Metrics/BlockLength
13
11
  namespace :run_rspec do
12
+ include ReactOnRails::TaskHelpers
13
+
14
14
  spec_dummy_dir = File.join("spec", "dummy")
15
15
 
16
16
  desc "Run RSpec for top level only"
@@ -82,6 +82,7 @@ namespace :run_rspec do
82
82
  puts "Completed all RSpec tests"
83
83
  end
84
84
  end
85
+ # rubocop:enable Metrics/BlockLength
85
86
 
86
87
  desc "js tests (same as 'yarn run test')"
87
88
  task :js_tests do
@@ -119,9 +120,7 @@ def run_tests_in(dir, options = {})
119
120
 
120
121
  command_name = options.fetch(:command_name, path.basename)
121
122
  rspec_args = options.fetch(:rspec_args, "")
122
- # rubocop:disable Performance/UnfreezeString
123
123
  env_vars = "#{options.fetch(:env_vars, '')} TEST_ENV_COMMAND_NAME=\"#{command_name}\"".dup
124
- # rubocop:enable Performance/UnfreezeString
125
124
  env_vars << "COVERAGE=true" if ENV["USE_COVERALLS"]
126
125
  sh_in_dir(path.realpath, "#{env_vars} bundle exec rspec #{rspec_args}")
127
126
  end
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  s.require_paths = ["lib"]
25
25
 
26
- s.required_ruby_version = ">= 2.0.0"
26
+ s.required_ruby_version = ">= 2.1.0"
27
27
 
28
28
  s.add_dependency "addressable"
29
29
  s.add_dependency "connection_pool"
@@ -48,3 +48,4 @@ Gem::Specification.new do |s|
48
48
  s.add_development_dependency "rake", "~> 10.0"
49
49
  s.add_development_dependency "rspec"
50
50
  end
51
+ # rubocop:enable Metrics/BlockLength
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.0.2
4
+ version: 10.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Gordon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-11 00:00:00.000000000 Z
11
+ date: 2018-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -324,6 +324,7 @@ files:
324
324
  - ".travis.yml"
325
325
  - CHANGELOG.md
326
326
  - CONTRIBUTING.md
327
+ - Dockerfile_tests
327
328
  - Gemfile
328
329
  - Gemfile.rails32
329
330
  - KUDOS.md
@@ -334,10 +335,12 @@ files:
334
335
  - SUMMARY.md
335
336
  - app/helpers/react_on_rails_helper.rb
336
337
  - book.json
338
+ - docker-compose.yml
337
339
  - docs/LICENSE.md
338
340
  - docs/additional-reading/angular-js-integration-migration.md
339
341
  - docs/additional-reading/asset-pipeline.md
340
342
  - docs/additional-reading/babel.md
343
+ - docs/additional-reading/caching-and-performance.md
341
344
  - docs/additional-reading/code-splitting.md
342
345
  - docs/additional-reading/elastic-beanstalk.md
343
346
  - docs/additional-reading/foreman-issues.md
@@ -464,7 +467,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
464
467
  requirements:
465
468
  - - ">="
466
469
  - !ruby/object:Gem::Version
467
- version: 2.0.0
470
+ version: 2.1.0
468
471
  required_rubygems_version: !ruby/object:Gem::Requirement
469
472
  requirements:
470
473
  - - ">="
@@ -472,7 +475,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
472
475
  version: '0'
473
476
  requirements: []
474
477
  rubyforge_project:
475
- rubygems_version: 2.6.12
478
+ rubygems_version: 2.7.2
476
479
  signing_key:
477
480
  specification_version: 4
478
481
  summary: Rails with react server rendering with webpack.