react_on_rails 12.0.0.pre.beta.1 → 12.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/.travis.yml +6 -4
  4. data/CHANGELOG.md +27 -17
  5. data/README.md +77 -79
  6. data/SUMMARY.md +1 -1
  7. data/docs/additional-reading/converting-from-custom-webpack-config-to-rails-webpacker-config.md +10 -0
  8. data/docs/additional-reading/react-router.md +1 -1
  9. data/docs/additional-reading/server-rendering-tips.md +4 -1
  10. data/docs/api/javascript-api.md +3 -3
  11. data/docs/api/redux-store-api.md +2 -2
  12. data/docs/api/view-helpers-api.md +4 -4
  13. data/docs/basics/configuration.md +28 -17
  14. data/docs/basics/deployment.md +2 -3
  15. data/docs/basics/heroku-deployment.md +24 -0
  16. data/docs/basics/hmr-and-hot-reloading-with-the-webpack-dev-server.md +49 -0
  17. data/docs/basics/i18n.md +3 -3
  18. data/docs/basics/installation-into-an-existing-rails-app.md +2 -7
  19. data/docs/basics/recommended-project-structure.md +5 -22
  20. data/docs/basics/render-functions-and-railscontext.md +1 -1
  21. data/docs/basics/rspec-configuration.md +27 -16
  22. data/docs/basics/upgrading-react-on-rails.md +35 -13
  23. data/docs/basics/webpack-configuration.md +3 -7
  24. data/docs/misc/doctrine.md +1 -1
  25. data/docs/outdated/code-splitting.md +3 -3
  26. data/docs/outdated/how-react-on-rails-works.md +8 -4
  27. data/docs/outdated/manual-installation-overview.md +1 -1
  28. data/docs/outdated/rails-assets.md +0 -7
  29. data/docs/tutorial.md +40 -30
  30. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-hmr +17 -9
  31. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +4 -1
  32. data/lib/react_on_rails/configuration.rb +45 -6
  33. data/lib/react_on_rails/helper.rb +8 -8
  34. data/lib/react_on_rails/locales/base.rb +8 -0
  35. data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +1 -1
  36. data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +17 -0
  37. data/lib/react_on_rails/version.rb +1 -1
  38. data/lib/react_on_rails/webpacker_utils.rb +6 -0
  39. data/lib/tasks/assets.rake +47 -8
  40. data/lib/tasks/locale.rake +1 -5
  41. data/package.json +1 -1
  42. data/rakelib/examples.rake +1 -1
  43. data/rakelib/lint.rake +1 -1
  44. data/rakelib/release.rake +1 -3
  45. data/react_on_rails.gemspec +1 -0
  46. data/yarn.lock +260 -109
  47. metadata +21 -5
  48. data/docs/outdated/heroku-deployment.md +0 -86
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f53b8097c4c41fa99e2e91a3aca2b875725a657fc93092624fd3e6d4f022164f
4
- data.tar.gz: 85d6d6da3bba2c596b80e2fac4b260be0ee300a0acf9db4e9f14144cbf35f1a7
3
+ metadata.gz: 83e519532dfba4ffcb23379c8d757d4d299aaa11247c718e310e257e3bca3291
4
+ data.tar.gz: d328b53abce54b4deb4481addaaef242b6b531c493aa3154784fa8f87f55e7c0
5
5
  SHA512:
6
- metadata.gz: 6b3b2081577a1f5adee8c818b2bbe9cb10f3f321ba0b2eec5477040af9033bd784f662f6639365f0b197185c7d5d93d58c1f5274c0094bb1998484011d4e3b1a
7
- data.tar.gz: '01965e573de93892c992bb8045615ce792dd41ffae7198a0841eab3bb356d144aa0e8b7265d648c8053e551b2e0d6c80ff08c830d3f95425828e5540d93befcd'
6
+ metadata.gz: e183bc2eaed29538422fbe0984177f9e64dcb7501d96f971e1a1887aae596e9fe2519d78d44c6517af07abe2db44632ba38879e070966641b1faac5e6e984e08
7
+ data.tar.gz: 6ab4afd6786b2539428dffcbad518dd0e3cd1111a61d0b81891a715d665e5c7e6d4053d3e344d770808422abb720c07259bd537f6bfe1b5a59f0e0127e96b2ac
@@ -10,6 +10,7 @@ AllCops:
10
10
  - '**/config.ru'
11
11
  - 'Gemfile'
12
12
  - '**/*.rb'
13
+ - '**/*.rake'
13
14
 
14
15
  Exclude:
15
16
  - 'vendor/**/*'
@@ -35,15 +35,17 @@ before_install:
35
35
 
36
36
  install:
37
37
  - travis_retry gem install bundler -v '>2'
38
- - travis_retry nvm install 13.9.0
38
+ - travis_retry nvm install 14
39
39
  - node -v
40
40
  - travis_retry npm i -g yarn
41
- - travis_retry bundle install
42
41
  - travis_retry yarn global add yalc
42
+ - travis_retry yarn
43
+ - travis_retry bundle install
44
+ - travis_retry yarn run build
43
45
  - travis_retry yalc publish
44
- - travis_retry cd spec/dummy && yalc add react-on-rails
46
+ - cd spec/dummy/client
47
+ - travis_retry yalc add react-on-rails
45
48
  - travis_retry yarn
46
- - travis_retry cd ../.. && yarn run build
47
49
  - bundle exec rake prepare_for_ci
48
50
 
49
51
  before_script:
@@ -4,27 +4,30 @@ All notable changes to this project's source code will be documented in this fil
4
4
  Migration instructions for the major updates can be found [here](docs/basics/upgrading-react-on-rails.md#upgrading-to-version-9.md). Some smaller migration information can be found here.
5
5
 
6
6
  ## Need Help Migrating?
7
- If you would like help in migrating between React on Rails versions or help with implementing server rendering, please contact [justin@shakacode.com](mailto:justin@shakacode.com) for information about our [ShakaCode Pro Support](https://www.shakacode.com/work/shakacode-pro-support.pdf).
7
+ If you would like help in migrating between React on Rails versions or help with implementing server rendering, please contact [justin@shakacode.com](mailto:justin@shakacode.com) for information about our [React on Rails Pro Support Options](https://www.shakacode.com/react-on-rails-pro).
8
8
 
9
9
  We specialize in helping companies to quickly and efficiently move from versions before 9 to current. The older versions use the Rails asset pipeline to package client assets. The current and recommended way is to use Webpack 4 for asset preparation. You may also need help migrating from the `rails/webpacker`'s Webpack configuration to a better setup ready for Server Side Rendering.
10
10
 
11
11
  ## Contributors
12
12
  Please follow the recommendations outlined at [keepachangelog.com](http://keepachangelog.com/). Please use the existing headings and styling as a guide, and add a link for the version diff at the bottom of the file. Also, please update the `Unreleased` link to compare to the latest release version.
13
13
 
14
- ## [Unreleased]
14
+ ## Versions
15
+ ### [Unreleased]
15
16
  Changes since last non-beta release.
16
17
 
17
18
  *Please add entries here for your pull requests that are not yet released.*
19
+ ### [12.0.1] - 2020-07-09
20
+ #### Fixed
21
+ - Changed invocation of webpacker:clean to use a very large number of versions so it does not acidentally delete the server-bundle.js. [PR 1306](https://github.com/shakacode/react_on_rails/pull/1306) by By [justin808](https://github.com/justin808).
18
22
 
19
- ## UPCOMING 12.0 RELEASE
20
-
21
- #### Improved
22
- * Generator supports React Hooks
23
-
24
-
23
+ ### [12.0.0] - 2020-07-08
24
+ For upgrade instructions, see [docs/basics/upgrading-react-on-rails.md](./docs/basics/upgrading-react-on-rails.md).
25
25
 
26
- ### [12.0.0.pre.beta.0]
27
- Gem version: 12.0.0.pre.beta.0 and npm version 12.0.0-beta.0 released! Please try this out!
26
+ #### Major Improvements
27
+ 1. **React Hooks Support** for top level components
28
+ 2. **Typescript bindings**
29
+ 3. **rails/webpacker** "just works" with React on Rails by default.
30
+ 4. i18n support for generating a JSON file rather than a JS file.
28
31
 
29
32
  #### BREAKING CHANGE
30
33
  In order to solve the issues regarding React Hooks compatibility, the number of parameters
@@ -34,10 +37,17 @@ set JavaScript property `renderFunction` on the function for which you want to r
34
37
  invoked to return the React component. In that case, you won't need to pass any unused params.
35
38
  [PR 1268](https://github.com/shakacode/react_on_rails/pull/1268) by [justin808](https://github.com/justin808)
36
39
 
37
- See [docs/basics/upgrading-react-on-rails](./docs/basics/upgrading-react-on-rails#upgrading-to-v12)
40
+ See [docs/basics/upgrading-react-on-rails](./docs/basics/upgrading-react-on-rails.md#upgrading-to-v12)
38
41
  for details.
39
42
 
40
- * Requires the use of rails/webpacker helpers
43
+ #### Other Updates
44
+ * `react_on_rails` fully supports `rails/webpacker`. The example test app in `spec/dummy` was recently converted over to use rails/webpacker v4+. It's a good example of how to leverage rails/webpacker's webpack configuration for server-side rendering.
45
+ * Changed the precompile task to use the rails/webpacker one by default
46
+ * Updated generators to use React hooks
47
+ * Requires the use of rails/webpacker view helpers
48
+ * If the webpacker webpack config files exist, then React on Rails will not override the default
49
+ assets:precompile setup by rails/webpacker. If you are not using the rails/webpacker setup for webpack,
50
+ then be sure to remove the JS files inside of config/webpack, like `config/webpack/production.js.`
41
51
  * Removed **env_javascript_include_tag** and **env_stylesheet_link_tag** as these are replaced by view helpers
42
52
  from rails/webpacker
43
53
  * Removal of support for old Rubies and Rails.
@@ -57,13 +67,12 @@ for details.
57
67
  * Added support to export locales in JSON format. New option added `i18n_output_format` which allows to
58
68
  specify locales format either `JSON` or `JS`. **`JSON` format is now the default.**
59
69
 
60
- Use this config setting to get the old behavior: config.i18n_output_format = 'js'
70
+ **Use this config setting to get the old behavior: config.i18n_output_format = 'js'**
61
71
 
62
72
  [PR 1271](https://github.com/shakacode/react_on_rails/pull/1271) by [ashgaliyev](https://github.com/ashgaliyev).
63
73
 
64
- #### Improved
65
74
  - Added Typescript definitions to the Node package. By [justin808](https://github.com/justin808) and [judahmeek](https://github.com/judahmeek) in [PR 1287](https://github.com/shakacode/react_on_rails/pull/1287).
66
- - Removed unnecessary restriction to keep the server bundle in the same directory with the client bundles. Rails/webpacker 4 has an advanced cleanup that will remove any files in the directory of other webpack files. Removing this restriction allows the server bundle to be created in a sibling directory. By [justin808](https://github.com/shakacode/react_on_rails/pull/1240).
75
+ - Removed restriction to keep the server bundle in the same directory with the client bundles. Rails/webpacker 4 has an advanced cleanup that will remove any files in the directory of other webpack files. Removing this restriction allows the server bundle to be created in a sibling directory. By [justin808](https://github.com/shakacode/react_on_rails/pull/1240).
67
76
 
68
77
  ### [11.3.0] - 2019-05-24
69
78
  #### Added
@@ -921,8 +930,9 @@ Best done with Object destructing:
921
930
  ##### Fixed
922
931
  - Fix several generator related issues.
923
932
 
924
- [Unreleased]: https://github.com/shakacode/react_on_rails/compare/12.0.0-beta.0...master
925
- [12.0.0.pre.beta.0]: https://github.com/shakacode/react_on_rails/compare/11.3.0...12.0.0-beta.0
933
+ [Unreleased]: https://github.com/shakacode/react_on_rails/compare/12.0.1...master
934
+ [12.0.1]: https://github.com/shakacode/react_on_rails/compare/12.0.0...12.0.1
935
+ [12.0.0]: https://github.com/shakacode/react_on_rails/compare/11.3.0...12.0.0
926
936
  [11.3.0]: https://github.com/shakacode/react_on_rails/compare/11.2.2...11.3.0
927
937
  [11.2.2]: https://github.com/shakacode/react_on_rails/compare/11.2.1...11.2.2
928
938
  [11.2.1]: https://github.com/shakacode/react_on_rails/compare/11.1.8...11.2.1
data/README.md CHANGED
@@ -11,30 +11,37 @@
11
11
 
12
12
  [![License](https://img.shields.io/badge/license-mit-green.svg)](./LICENSE.md) [![Build Status](https://travis-ci.org/shakacode/react_on_rails.svg?branch=master)](https://travis-ci.org/shakacode/react_on_rails) [![Gem Version](https://badge.fury.io/rb/react_on_rails.svg)](https://badge.fury.io/rb/react_on_rails) [![npm version](https://badge.fury.io/js/react-on-rails.svg)](https://badge.fury.io/js/react-on-rails) [![Code Climate](https://codeclimate.com/github/shakacode/react_on_rails/badges/gpa.svg)](https://codeclimate.com/github/shakacode/react_on_rails) [![Coverage Status](https://coveralls.io/repos/shakacode/react_on_rails/badge.svg?branch=master&service=github)](https://coveralls.io/github/shakacode/react_on_rails?branch=master) [![](https://ruby-gem-downloads-badge.herokuapp.com/react_on_rails?type=total)](https://rubygems.org/gems/react_on_rails)
13
13
 
14
- *These are the docs for React on Rails 12, coming soon. To see the version 11 docs, [click here](https://github.com/shakacode/react_on_rails/tree/11.3.0).*
14
+ *These are the docs for React on Rails 12. To see the version 11 docs, [click here](https://github.com/shakacode/react_on_rails/tree/11.3.0).*
15
15
 
16
16
  #### News
17
- **June 12, 2020**:
18
- 1. Gem version: 12.0.0.pre.beta.0 and npm version 12.0.0-beta.0 released! Please try this out!
19
- Major enhancements:
20
- 1. Typescript bindings
21
- 2. Proper support for React Hooks
22
- 3. i18n support for generating a JSON file rather than a JS file.
23
- 2. See Justin's RailsConf talk: [Webpacker, It-Just-Works, But How?](http://railsconf.com/2020/video/justin-gordon-webpacker-it-just-works-but-how).
24
-
25
- **April 2, 2020**:
17
+ **July 8, 2020**: Release v12 of React on Rails.
18
+
19
+ **Major Improvements**
20
+
21
+ 1. **React Hooks Support** for top level components
22
+ 2. **Typescript bindings**
23
+ 3. **rails/webpacker** "just works" with React on Rails by default.
24
+ 4. i18n support for generating a JSON file rather than a JS file.
25
+
26
+ Be sure to see the [CHANGELOG.md](./CHANGELOG.md) and read the upgrade instructions:
27
+ [docs/basics/upgrading-react-on-rails](./docs/basics/upgrading-react-on-rails.md#upgrading-to-v12).
28
+
29
+ * See Justin's RailsConf talk: [Webpacker, It-Just-Works, But How?](http://railsconf.com/2020/video/justin-gordon-webpacker-it-just-works-but-how).
26
30
  * Are you interested in support for React on Rails? If so check out [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro).
27
31
  * HMR is working with [Loadable Components](https://loadable-components.com) for a both amazing hot-reloading developer experience and great runtime performance. Please [email me](mailto:justin@shakacode.com) if you'd like to use [Loadable Components Code Splitting](https://loadable-components.com/docs/code-splitting/) to speed up your app by reducing your bundle sizes and lazily loading the code that's needed.
28
- * `react_on_rails` fully supports `rails/webpacker`. The example test app in `spec/dummy` was recently converted over to use rails/webpacker v4. It's a good example of how to leverage rails/webpacker's webpack configuration.
32
+ * `react_on_rails` fully supports `rails/webpacker`. The example test app in `spec/dummy` was recently converted over to use rails/webpacker v4+. It's a good example of how to leverage rails/webpacker's webpack configuration.
29
33
 
30
34
  ---
31
35
 
32
36
  #### About
33
37
  React on Rails integrates Rails with (server rendering of) Facebook's [React](https://github.com/facebook/react) front-end framework.
34
38
 
35
- This project is sponsored by the software consulting firm [ShakaCode](https://www.shakacode.com). We focus on React front-ends, often with Ruby on Rails or Gatsby. The best way to see what we do is to see the details of [our recent work](https://www.shakacode.com/recent-work).
39
+ This project is sponsored by the software consulting firm [ShakaCode](https://www.shakacode.com). We focus on React front-ends, often with Ruby on Rails or Gatsby, using TypeScript or ReasonML. The best way to see what we do is to see the details of [our recent work](https://www.shakacode.com/recent-work).
36
40
 
37
- Interested in optimizing your webpack setup for React on Rails including code splitting with react-router v4, webpack v4, and react-loadable with server side rendering? We just did this for Popmenu, [lowering Heroku costs 20-25% while getting a 73% decrease in average response times](https://www.shakacode.com/recent-work/popmenu/).
41
+ Interested in optimizing your webpack setup for React on Rails including code
42
+ splitting with [react-router](https://github.com/ReactTraining/react-router#readme),
43
+ and [loadable-components](https://loadable-components.com/) with server-side rendering?
44
+ We just did this for Popmenu, [lowering Heroku costs 20-25% while getting a 73% decrease in average response times](https://www.shakacode.com/recent-work/popmenu/).
38
45
 
39
46
  Feel free to contact Justin Gordon, [justin@shakacode.com](mailto:justin@shakacode.com), maintainer of React on Rails, for more information.
40
47
 
@@ -44,21 +51,20 @@ Feel free to contact Justin Gordon, [justin@shakacode.com](mailto:justin@shakaco
44
51
 
45
52
  ## Project Objective
46
53
 
47
- To provide an opinionated and optimal framework for integrating Ruby on Rails with React via the [**Webpacker**](https://github.com/rails/webpacker) gem especially in regards to React Server Rendering.
54
+ To provide a high performance framework for integrating Ruby on Rails with React via the [**Webpacker**](https://github.com/rails/webpacker) gem especially in regards to React Server-Side Rendering for better SEO and improved performance.
48
55
 
49
56
  ## Features and Why React on Rails?
50
57
 
51
- Given that rails/webpacker gem already provides basic React integration, why would you use "React on Rails"?
58
+ Given that `rails/webpacker` gem already provides basic React integration, why would you use "React on Rails"?
52
59
 
53
- 1. Server rendering, often used for SEO crawler indexing and UX performance, is not offered by rails/webpacker.
54
- 1. The easy passing of props directly from your Rails view to your React components rather than having your Rails view load and then make a separate request to your API.
55
- 1. [Redux](https://github.com/reactjs/redux) and [React Router](https://github.com/reactjs/react-router) integration with server-side-rendering.
60
+ 1. Easy passing of props directly from your Rails view to your React components rather than having your Rails view load and then make a separate request to your API.
61
+ 1. Tight integration with [rails/webpacker](https://github.com/rails/webpacker).
62
+ 1. Server-Side Rendering (SSR), often used for SEO crawler indexing and UX performance, is not offered by `rails/webpacker`.
63
+ 1. [Redux](https://github.com/reactjs/redux) and [React Router](https://github.com/ReactTraining/react-router#readme) integration with server-side-rendering.
56
64
  1. [Internationalization (I18n) and (localization)](https://github.com/shakacode/react_on_rails/blob/master/docs/basics/i18n.md)
57
- 1. [RSpec Test Helpers Configuration](docs/basics/rspec-configuration.md) to ensure your Webpack bundles are ready for tests. _(and for [Minitest](docs/basics/minitest-configuration.md))._
58
65
  1. A supportive community. This [web search shows how live public sites are using React on Rails](https://publicwww.com/websites/%22react-on-rails%22++-undeveloped.com/).
59
66
  1. [Reason ML Support](https://github.com/shakacode/reason-react-on-rails-example).
60
67
 
61
-
62
68
  See the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) for an example of a live implementation and code.
63
69
 
64
70
  ## ShakaCode Forum Premium Content
@@ -74,7 +80,7 @@ _Requires creating a free account._
74
80
 
75
81
  ## Prerequisites
76
82
 
77
- React on Rails supports older versions of Rails back to 3.x. Rails/webpacker requires version 4.2+.
83
+ Ruby on Rails >=5 and rails/webpacker 4.2+.
78
84
 
79
85
  ## Getting Started
80
86
 
@@ -89,23 +95,10 @@ Note, the best way to understand how to use ReactOnRails is to study a few simpl
89
95
 
90
96
  *See also [the instructions for installing into an existing Rails app](docs/basics/installation-into-an-existing-rails-app.md).*
91
97
 
92
- 1. Create a new Rails app:
93
-
94
- ``````bash
95
- $ rails new my-app --webpack=react
96
- $ cd my-app
97
- ``````
98
-
99
98
  2. Add the `react_on_rails` gem to Gemfile:
100
99
 
101
- ```ruby
102
- gem 'react_on_rails', '11.1.4' # Use the exact gem version to match npm version
103
- ```
104
-
105
- 3. Install the `react_on_rails` gem:
106
-
107
100
  ```bash
108
- $ bundle install
101
+ bundle add react_on_rails --strict
109
102
  ```
110
103
 
111
104
  4. Commit this to git (or else you cannot run the generator unless you pass the option `--ignore-warnings`).
@@ -113,13 +106,13 @@ Note, the best way to understand how to use ReactOnRails is to study a few simpl
113
106
  5. Run the generator:
114
107
 
115
108
  ```bash
116
- $ rails generate react_on_rails:install
109
+ rails generate react_on_rails:install
117
110
  ```
118
111
 
119
112
  6. Start the app:
120
113
 
121
114
  ```bash
122
- $ rails s
115
+ rails s
123
116
  ```
124
117
 
125
118
  7. Visit http://localhost:3000/hello_world.
@@ -138,14 +131,19 @@ Below is the line where you turn server rendering on by setting `prerender` to t
138
131
  <%= react_component("HelloWorld", props: @hello_world_props, prerender: false) %>
139
132
  ```
140
133
 
134
+ Note, if you got an error in your console regarding "ReferenceError: window is not defined",
135
+ then you need to edit `config/webpacker.yml` and set `hmr: false` and `inline: false`.
136
+ See [rails/webpacker PR 2644](https://github.com/rails/webpacker/pull/2644) for a fix for this
137
+ issue.
138
+
141
139
  ## Basic Usage
142
140
 
143
141
  ### Configuration
144
142
 
145
143
  * Configure `config/initializers/react_on_rails.rb`. You can adjust some necessary settings and defaults. See file [docs/basics/configuration.md](docs/basics/configuration.md) for documentation of all configuration options.
146
- * Configure `config/webpacker.yml`. If you used the generator and the default webpacker setup, you don't need to touch this file. If you are customizing your setup, then consult the [spec/dummy/config/webpacker.yml](./spec/dummy/config/webpacker.yml) example
147
- * Set `compile: false` for all envs
148
- * Your `public_output_path` must match your Webpack configuration for `output` of your bundles.
144
+ * Configure `config/webpacker.yml`. If you used the generator and the default webpacker setup, you don't need to touch this file. If you are customizing your setup, then consult the [spec/dummy/config/webpacker.yml](./spec/dummy/config/webpacker.yml) example or the official default [webpacker.yml](https://github.com/rails/webpacker/blob/master/lib/install/config/webpacker.yml).
145
+ * Tip: set `compile: false` for development if you know that you'll always be compiling with a watch process. Otherwise, every request will check if compilation is needed.
146
+ * Your `public_output_path` must match your custom Webpack configuration for `output` of your bundles.
149
147
  * Only set `cache_manifest` to `true` in your production env.
150
148
 
151
149
  ## Including your React Component on your Rails Views
@@ -170,7 +168,7 @@ Below is the line where you turn server rendering on by setting `prerender` to t
170
168
  ReactOnRails.register({ HelloWorld });
171
169
  ```
172
170
 
173
- Exposing your component in this way is how React on Rails is able to reference your component from a Rails view. You can expose as many components as you like, as long as their names do not collide. See below for the details of how you expose your components via the react_on_rails webpack configuration.
171
+ Exposing your component in this way is how React on Rails is able to reference your component from a Rails view. You can expose as many components as you like, as long as their names do not collide. See below for the details of how you expose your components via the react_on_rails webpack configuration. You may call `ReactOnRails.register` many times.
174
172
 
175
173
  - `@some_props` can be either a hash or JSON string. This is an optional argument assuming you do not need to pass any options (if you want to pass options, such as `prerender: true`, but you do not want to pass any properties, simply pass an empty hash `{}`). This will make the data available in your component:
176
174
 
@@ -179,7 +177,7 @@ Below is the line where you turn server rendering on by setting `prerender` to t
179
177
  <%= react_component("HelloWorld", props: { name: "Stranger" }) %>
180
178
  ```
181
179
 
182
- - This is what your HelloWorld.js file might contain. The railsContext is always available for any parameters that you _always_ want available for your React components. It has _nothing_ to do with the concept of the [React Context](https://reactjs.org/docs/context.html). See [render functions and the RailsContext](docs/basics/render-functions-and-railscontext.md) for more details on this topic.
180
+ - This is what your HelloWorld.js file might contain. The railsContext is always available for any parameters that you _always_ want available for your React components. It has _nothing_ to do with the concept of the [React Context](https://reactjs.org/docs/context.html). See [Render-Functions and the RailsContext](docs/basics/render-functions-and-railscontext.md) for more details on this topic.
183
181
 
184
182
  ```js
185
183
  import React from 'react';
@@ -197,32 +195,6 @@ Below is the line where you turn server rendering on by setting `prerender` to t
197
195
 
198
196
  See the [View Helpers API](./docs/api/view-helpers-api.md) for more details on `react_component` and its sibling function `react_component_hash`.
199
197
 
200
- ## Fragment Caching
201
-
202
- Fragment caching is a [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro) feature. Fragment caching is a **HUGE** performance booster for your apps. Use the `cached_react_component` and `cached_react_component_hash`. The API is the same as `react_component` and `react_component_hash`, but for 2 differences:
203
-
204
- 1. The `cache_key` takes the same parameters as any Rails `cache` view helper.
205
- 1. The **props** are passed via a block so that evaluation of the props is not done unless the cache is broken. Suppose you put your props calculation into some method called `some_slow_method_that_returns_props`:
206
-
207
- ```ruby
208
- <%= cached_react_component("App", cache_key: [@user, @post], prerender: true) do
209
- some_slow_method_that_returns_props
210
- end %>
211
- ```
212
-
213
- Such fragment caching saves a ton of CPU work for your web server and greatly reduces the request time. It completely skips the evaluation costs of:
214
-
215
- 1. Database calls to compute the props.
216
- 2. Serialization the props values hash into a JSON string for evaluating JavaScript to server render.
217
- 3. Costs associated with evaluating JavaScript from your Ruby code.
218
- 4. Creating the HTML string containing the props and the server-rendered JavaScript code.
219
-
220
- Note, even without server rendering (without step 3 above), fragment caching is still effective.
221
-
222
- ## Integration with Node.js for Server Rendering
223
-
224
- Default server rendering is done by ExecJS. If you want to use a Node.js server for better performing server rendering, [email justin@shakacode.com](mailto:justin@shakacode.com). ShakaCode has built a premium Node rendering server that is part of [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro).
225
-
226
198
  ## Globally Exposing Your React Components
227
199
 
228
200
  For the React on Rails view helper `react_component` to use your React components, you will have to **register** them in your JavaScript code.
@@ -250,15 +222,15 @@ For details on techniques to use different code for client and server rendering,
250
222
 
251
223
  You have two ways to specify your React components. You can either register the React component (either function or class component) directly, or you can create a function that returns a React component, which we using the name of a "render-function". Creating a render-function allows:
252
224
 
253
- 1. You have access to the `railsContext`. See documentation for the railsContext in terms of why you might need it. You **need** a render function to access the `railsContext`.
225
+ 1. You to have access to the `railsContext`. See [documentation for the railsContext](./docs/basics/render-functions-and-railscontext.md) in terms of why you might need it. You **need** a Render-Function to access the `railsContext`.
254
226
  2. You can use the passed-in props to initialize a redux store or set up react-router.
255
227
  3. You can return different components depending on what's in the props.
256
228
 
257
- Note, the return value of a **render function** should be either a React Function or Class Component, or an object representing server rendering results.
229
+ Note, the return value of a **Render-Function** should be either a React Function or Class Component, or an object representing server rendering results.
258
230
 
259
231
  Do not return a React Element (JSX).
260
232
 
261
- ReactOnRails will automatically detect a registered render function by the fact that the function takes
233
+ ReactOnRails will automatically detect a registered Render-Function by the fact that the function takes
262
234
  more than 1 parameter. In other words, if you want the ability to provide a function that returns the
263
235
  React component, then you need to specify at least a second parameter. This is the `railsContext`.
264
236
  If you're not using this parameter, declare your function with the unused param:
@@ -272,13 +244,13 @@ const MyComponentGenerator = (props, _railsContext) => {
272
244
  }
273
245
  ```
274
246
 
275
- Thus, there is no difference between registering a React function or class Component versus a "render function."
247
+ Thus, there is no difference between registering a React Function Component or class Component versus a "Render-Function." Just call `ReactOnRails.register`.
276
248
 
277
- ## react_component_hash for render functions
249
+ ## react_component_hash for Render-Functions
278
250
 
279
- Another reason to use a render function is that sometimes in server rendering, specifically with React Router, you need to return the result of calling ReactDOMServer.renderToString(element). You can do this by returning an object with the following shape: { renderedHtml, redirectLocation, error }. Make sure you use this function with `react_component_hash`.
251
+ Another reason to use a Render-Function is that sometimes in server rendering, specifically with React Router, you need to return the result of calling ReactDOMServer.renderToString(element). You can do this by returning an object with the following shape: { renderedHtml, redirectLocation, error }. Make sure you use this function with `react_component_hash`.
280
252
 
281
- For server rendering, if you wish to return multiple HTML strings from a render function, you may return an Object from your render function with a single top-level property of `renderedHtml`. Inside this Object, place a key called `componentHtml`, along with any other needed keys. An example scenario of this is when you are using side effects libraries like [React Helmet](https://github.com/nfl/react-helmet). Your Ruby code will get this Object as a Hash containing keys componentHtml and any other custom keys that you added:
253
+ For server rendering, if you wish to return multiple HTML strings from a Render-Function, you may return an Object from your Render-Function with a single top-level property of `renderedHtml`. Inside this Object, place a key called `componentHtml`, along with any other needed keys. An example scenario of this is when you are using side effects libraries like [React Helmet](https://github.com/nfl/react-helmet). Your Ruby code will get this Object as a Hash containing keys componentHtml and any other custom keys that you added:
282
254
 
283
255
  ```js
284
256
  { renderedHtml: { componentHtml, customKey1, customKey2} }
@@ -340,16 +312,42 @@ React on Rails Pro provides Node server rendering, fragment caching, code-splitt
340
312
 
341
313
  The [React on Rails Pro Support Plan](https://www.shakacode.com/react-on-rails-pro) can help!
342
314
 
343
- * Optimizing your webpack setup to Webpack v4 for React on Rails including code splitting with react-router v4, webpack v4, and react-loadable.
344
- * Upgrading your app to use the current Webpack setup that skips the Sprockets asset pipeline.
315
+ * Optimizing your webpack setup to the latest Webpack for React on Rails including code splitting with loadable-components.
316
+ * Upgrading your app to use the current `rails/webpacker` setup that skips the Sprockets asset pipeline.
345
317
  * Better performance client and server side.
346
- * Best practices based on over four years of React on Rails experience.
318
+ * Best practices based on over 6 years of React on Rails experience on many production projects.
347
319
  * Using [Reason](https://reasonml.github.io/) with (or without) React on Rails.
348
320
 
349
- ShakaCode can also help you with your custom software development needs. We specialize in marketplace and e-commerce applications that utilize both Rails and React. Because we own [HawaiiChee.com](https://www.hawaiichee.com), we can leverage that code for your app!
321
+ ShakaCode can also help you with your custom software development needs. We specialize in marketplace and e-commerce applications that utilize both Rails and React. Because we own [HiChee.com](https://hichee.com), we can leverage that code for your app!
350
322
 
351
323
  Please email Justin Gordon [justin@shakacode.com](mailto:justin@shakacode.com), the maintainer of React on Rails, for more information.
352
324
 
325
+ ### Fragment Caching
326
+
327
+ Fragment caching is a [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro) feature. Fragment caching is a **HUGE** performance booster for your apps. Use the `cached_react_component` and `cached_react_component_hash`. The API is the same as `react_component` and `react_component_hash`, but for 2 differences:
328
+
329
+ 1. The `cache_key` takes the same parameters as any Rails `cache` view helper.
330
+ 1. The **props** are passed via a block so that evaluation of the props is not done unless the cache is broken. Suppose you put your props calculation into some method called `some_slow_method_that_returns_props`:
331
+
332
+ ```ruby
333
+ <%= cached_react_component("App", cache_key: [@user, @post], prerender: true) do
334
+ some_slow_method_that_returns_props
335
+ end %>
336
+ ```
337
+
338
+ Such fragment caching saves CPU work for your web server and greatly reduces the request time. It completely skips the evaluation costs of:
339
+
340
+ 1. Database calls to compute the props.
341
+ 2. Serialization the props values hash into a JSON string for evaluating JavaScript to server render.
342
+ 3. Costs associated with evaluating JavaScript from your Ruby code.
343
+ 4. Creating the HTML string containing the props and the server-rendered JavaScript code.
344
+
345
+ Note, even without server rendering (without step 3 above), fragment caching is still effective.
346
+
347
+ ## Integration with Node.js for Server Rendering
348
+
349
+ Default server rendering is done by ExecJS. If you want to use a Node.js server for better performing server rendering, [email justin@shakacode.com](mailto:justin@shakacode.com). ShakaCode has built a premium Node rendering server that is part of [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro).
350
+
353
351
  ## Testimonials for ShakaCode
354
352
  [HVMN Testimonial, by Paul Benigeri, October 12, 2018](./docs/testimonials/hvmn.md)
355
353
  > The price we paid for the consultation + the React on Rails pro license has already been made back a couple of times from hosting fees alone. The entire process was super hands off, and our core team was able to focus on shipping new feature during that sprint.
data/SUMMARY.md CHANGED
@@ -45,7 +45,7 @@
45
45
  + [AngularJS Integration and Migration to React on Rails](./docs/additional-reading/angular-js-integration-migration.md)
46
46
 
47
47
  ## **Deployment**
48
- + [Heroku Deployment](docs/outdated/heroku-deployment.md)
48
+ + [Heroku Deployment](docs/basics/heroku-deployment.md)
49
49
  + [Elastic Beanstalk Deployment](./docs/additional-reading/elastic-beanstalk.md)
50
50
 
51
51
  ## Outdated Non-Webpack Docs
@@ -0,0 +1,10 @@
1
+ # Converting from Custom Webpack Config to Rails Webpacker Config
2
+
3
+ 1. Compare your package.json and the dependencies in https://github.com/rails/webpacker/blob/master/package.json#L14-L48
4
+ and avoid any duplicates. We don't want different versions of the same packages.
5
+ We want the versions from rails/webpacker unless we specifically want to override them.
6
+ 2. Search the rails/webpacker repo for anything you're not sure about in terms of package names.
7
+ 3. run `bin/webpack` and make sure there are zero errors
8
+ 4. update webpack plugins and loaders to current or close to current
9
+ 5. Make sure that your bin/webpack and bin/webpacker match the latest on
10
+ https://github.com/rails/webpacker/tree/master/lib/install/bin
@@ -39,7 +39,7 @@ For a fleshed out integration of react_on_rails with react-router, check out [Re
39
39
 
40
40
  # Server Rendering Using React Router V4
41
41
 
42
- Your render function may not return an object with the property `renderedHtml`. Thus, you call
42
+ Your Render-Function may not return an object with the property `renderedHtml`. Thus, you call
43
43
  renderToString() and return an object with this property.
44
44
 
45
45
  This example **only applies to server rendering** and should be only used in the server side bundle.
@@ -13,7 +13,7 @@ Be sure to use mini_racer. See [issues/428](https://github.com/shakacode/react_o
13
13
  - You can conditionally avoid running code that references document by either checking if `window`
14
14
  is defined or using the "railsContext"
15
15
  your top level react component. Since the passed in props Hash from the view helper applies to
16
- client and server side code, the best way to do this is to use a render function.
16
+ client and server side code, the best way to do this is to use a Render-Function.
17
17
  - If you're serious about server rendering, it's worth the effort to have different entry points for client and server rendering. It's worth the extra complexity. The point is that you have separate files for top level client or server side, and you pass some extra option indicating that rendering is happening server side.
18
18
  - You can enable Node.js server rendering via [React on Rails Pro](https://github.com/shakacode/react_on_rails/wiki).
19
19
 
@@ -22,6 +22,9 @@ Be sure to use mini_racer. See [issues/428](https://github.com/shakacode/react_o
22
22
  1. First be sure your code works with server rendering disabled (`prerender: false`)
23
23
  2. Be sure that `config.trace` is true. You will get the server invocation code that renders your component. If you're not using Webpacker, you will also get the whole file used to setup the JavaScript context.
24
24
 
25
+ ## CSS
26
+ Server bundles must always have CSS Extracted
27
+
25
28
  ## setTimeout, setInterval, and clearTimeout
26
29
 
27
30
  These methods are polyfilled for server rendering to be no-ops. We log calls to these when in `trace` mode. In the past, some libraries, namely babel-polyfill, did call setTimout.