react_on_rails 12.0.4 → 12.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +12 -2
- data/.eslintrc +2 -0
- data/.github/workflows/lint-js-and-ruby.yml +3 -3
- data/.github/workflows/main.yml +6 -6
- data/.github/workflows/package-js-tests.yml +2 -2
- data/.github/workflows/rspec-package-specs.yml +2 -2
- data/.prettierrc +0 -3
- data/.rubocop.yml +40 -8
- data/CHANGELOG.md +38 -14
- data/CONTRIBUTING.md +3 -2
- data/Gemfile.development_dependencies +6 -9
- data/NEWS.md +0 -1
- data/README.md +59 -58
- data/Rakefile +1 -1
- data/docs/{basics → additional-details}/generator-details.md +1 -6
- data/docs/{outdated → additional-details}/manual-installation-overview.md +6 -6
- data/docs/{basics → additional-details}/migrating-from-react-rails.md +0 -0
- data/docs/{additional-reading → additional-details}/recommended-project-structure.md +0 -0
- data/docs/{additional-reading → additional-details}/updating-dependencies.md +0 -0
- data/docs/additional-details/upgrade-webpacker-v3-to-v4.md +10 -0
- data/docs/api/javascript-api.md +2 -2
- data/docs/api/redux-store-api.md +3 -3
- data/docs/api/view-helpers-api.md +7 -8
- data/docs/basics/client-vs-server-rendering.md +3 -3
- data/docs/basics/configuration.md +45 -25
- data/docs/basics/deployment.md +2 -2
- data/docs/{outdated → basics}/how-react-on-rails-works.md +8 -9
- data/docs/basics/installation-into-an-existing-rails-app.md +13 -6
- data/docs/basics/react-server-rendering.md +3 -3
- data/docs/basics/rspec-configuration.md +10 -10
- data/docs/{tutorial.md → basics/tutorial.md} +22 -30
- data/docs/basics/upgrading-react-on-rails.md +7 -7
- data/docs/basics/webpack-configuration.md +4 -6
- data/docs/contributor-info/linters.md +5 -6
- data/docs/contributor-info/pull-requests.md +2 -4
- data/docs/contributor-info/releasing.md +1 -1
- data/docs/{additional-reading → deployment}/elastic-beanstalk.md +0 -0
- data/docs/{basics → deployment}/heroku-deployment.md +0 -0
- data/docs/home.md +382 -0
- data/docs/{additional-reading → javascript}/angular-js-integration-migration.md +0 -0
- data/docs/{additional-reading → javascript}/asset-pipeline.md +0 -0
- data/docs/{additional-reading → javascript}/capistrano-deployment.md +0 -0
- data/docs/{outdated → javascript}/code-splitting.md +3 -3
- data/docs/{additional-reading → javascript}/converting-from-custom-webpack-config-to-rails-webpacker-config.md +3 -3
- data/docs/{additional-reading → javascript}/credits.md +0 -0
- data/docs/{additional-reading → javascript}/foreman-issues.md +0 -0
- data/docs/{additional-reading → javascript}/images.md +5 -6
- data/docs/{additional-reading → javascript}/node-dependencies-and-npm.md +0 -0
- data/docs/{additional-reading → javascript}/react-and-redux.md +0 -0
- data/docs/{additional-reading → javascript}/react-helmet.md +0 -0
- data/docs/{additional-reading → javascript}/react-router.md +0 -0
- data/docs/{additional-reading → javascript}/server-rendering-tips.md +0 -0
- data/docs/{additional-reading → javascript}/troubleshooting-when-using-webpacker.md +0 -0
- data/docs/{additional-reading → javascript}/webpack-v1-notes.md +0 -0
- data/docs/{additional-reading → javascript}/webpack.md +0 -0
- data/docs/{articles.md → misc/articles.md} +1 -1
- data/docs/misc/doctrine.md +5 -5
- data/docs/{coding-style → misc}/style.md +0 -0
- data/docs/{additional-reading → misc}/tips.md +0 -0
- data/docs/outdated/deferred-rendering.md +39 -0
- data/docs/outdated/rails-assets-relative-paths.md +3 -3
- data/docs/outdated/rails-assets.md +8 -8
- data/docs/outdated/rails3.md +2 -2
- data/docs/rails-webpacker-react-integration-options.md +182 -0
- data/docs/{additional-reading → rails}/convert-rails-5-api-only-app.md +1 -1
- data/docs/{additional-reading → rails}/rails-engine-integration.md +0 -0
- data/docs/{additional-reading → rails}/rails_view_rendering_from_inline_javascript.md +0 -0
- data/docs/{additional-reading → rails}/turbolinks.md +13 -1
- data/docs/testimonials/testimonials.md +6 -6
- data/lib/generators/react_on_rails/base_generator.rb +1 -1
- data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -1
- data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +4 -1
- data/lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb +1 -1
- data/lib/generators/react_on_rails/templates/dev_tests/spec/{features → system}/hello_world_spec.rb +2 -2
- data/lib/react_on_rails/helper.rb +23 -5
- data/lib/react_on_rails/locales/base.rb +13 -10
- data/lib/react_on_rails/prerender_error.rb +1 -1
- data/lib/react_on_rails/react_component/render_options.rb +16 -7
- data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +2 -0
- data/lib/react_on_rails/utils.rb +16 -2
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/react_on_rails/webpacker_utils.rb +5 -1
- data/lib/tasks/assets.rake +14 -5
- data/package.json +24 -29
- data/rakelib/release.rake +22 -6
- data/rakelib/run_rspec.rake +1 -1
- data/rakelib/task_helpers.rb +15 -2
- data/yarn.lock +2549 -5169
- metadata +39 -37
- data/.release-it.json +0 -3
- data/docs/additional-reading/upgrade-webpacker-v3-to-v4.md +0 -10
@@ -1,5 +1,5 @@
|
|
1
1
|
# RSpec Configuration
|
2
|
-
_Click [here for minitest](
|
2
|
+
_Click [here for minitest](https://www.shakacode.com/react-on-rails/docs/basics/minitest-configuration)_
|
3
3
|
|
4
4
|
# If your webpack configurations correspond to rails/webpacker's default setup
|
5
5
|
If you're able to configure your webpack configuration to be run by having your webpack configuration
|
@@ -8,12 +8,12 @@ compiled by webpack before running tests and during production deployment:
|
|
8
8
|
|
9
9
|
1. **Use rails/webpacker's compile option**: Configure your `config/webpacker.yml` so that `compile: true` is for `test` and `production`
|
10
10
|
environments. Ensure that your `source_path` is correct, or else `rails/webpacker` won't correctly
|
11
|
-
detect changes.
|
12
|
-
2. **Use the react_on_rails settings and helpers**. Use the settings in `config/initializers/react_on_rails.rb`. Refer to [docs/configuration](
|
11
|
+
detect changes.
|
12
|
+
2. **Use the react_on_rails settings and helpers**. Use the settings in `config/initializers/react_on_rails.rb`. Refer to [docs/configuration](https://www.shakacode.com/react-on-rails/docs/basics/configuration).
|
13
13
|
|
14
14
|
```yml
|
15
15
|
config.build_test_command = "NODE_ENV=test RAILS_ENV=test bin/webpack"
|
16
|
-
```
|
16
|
+
```
|
17
17
|
|
18
18
|
Which should you use? If you're already using the `rails/webpacker` way to configure webpack, then
|
19
19
|
you can keep things simple and use the `rails/webpacker` options.
|
@@ -25,7 +25,7 @@ Because you will probably want to run RSpec tests that rely on compiled webpack
|
|
25
25
|
As mentioned above, you can configure `compile: true` in `config/webpacker.yml` _if_ you've got configuration for
|
26
26
|
your webpack in the standard `rails/webpacker` spot of `config/webpack/<NODE_ENV>.js`
|
27
27
|
|
28
|
-
ReactOnRails also provides a helper method called `ReactOnRails::TestHelper.configure_rspec_to_compile_assets`. Call this method from inside of the `RSpec.configure` block in your `spec/rails_helper.rb` file, passing the config as an argument. See file [lib/react_on_rails/test_helper.rb](
|
28
|
+
ReactOnRails also provides a helper method called `ReactOnRails::TestHelper.configure_rspec_to_compile_assets`. Call this method from inside of the `RSpec.configure` block in your `spec/rails_helper.rb` file, passing the config as an argument. See file [lib/react_on_rails/test_helper.rb](https://github.com/shakacode/react_on_rails/tree/master/lib/react_on_rails/test_helper.rb) for more details. You can customize this to your particular needs by replacing any of the default components used by `ReactOnRails::TestHelper.configure_rspec_to_compile_assets`.
|
29
29
|
|
30
30
|
```ruby
|
31
31
|
RSpec.configure do |config|
|
@@ -44,22 +44,22 @@ If you are using Webpack to build CSS assets, you should do something like this
|
|
44
44
|
```
|
45
45
|
|
46
46
|
Please take note of the following:
|
47
|
-
- If you are using Webpacker, be **SURE** to configure the `source_path` in your `config/webpacker.yml` unless you are using the defaults for webpacker.
|
47
|
+
- If you are using Webpacker, be **SURE** to configure the `source_path` in your `config/webpacker.yml` unless you are using the defaults for webpacker.
|
48
48
|
|
49
49
|
- This utility uses your `build_test_command` to build the static generated files. This command **must not** include the `--watch` option. If you have different server and client bundle files, this command **must** create all the bundles. If you are using webpacker, the default value will come from the `config/webpacker.yml` value for the `public_output_path` and the `source_path`
|
50
50
|
|
51
|
-
- If you add an older file to your source files, that is already older than the produced output files, no new recompilation is done. The solution to this issue is to clear out your directory of webpack generated files when adding new source files that may have older dates.
|
51
|
+
- If you add an older file to your source files, that is already older than the produced output files, no new recompilation is done. The solution to this issue is to clear out your directory of webpack generated files when adding new source files that may have older dates.
|
52
52
|
|
53
|
-
- By default, the webpack processes look in the webpack generated files folder, configured via the `config/webpacker.yml` config values of `public_root_path` and `public_output_path`. If the webpack generated files folder is missing, is empty, or contains files in the `config.webpack_generated_files` list with `mtime`s older than any of the files in your `client` folder, the helper will recompile your assets.
|
53
|
+
- By default, the webpack processes look in the webpack generated files folder, configured via the `config/webpacker.yml` config values of `public_root_path` and `public_output_path`. If the webpack generated files folder is missing, is empty, or contains files in the `config.webpack_generated_files` list with `mtime`s older than any of the files in your `client` folder, the helper will recompile your assets.
|
54
54
|
|
55
55
|
The following `config/react_on_rails.rb` settings **must** match your setup:
|
56
56
|
```ruby
|
57
57
|
# Define the files we need to check for webpack compilation when running tests.
|
58
58
|
config.webpack_generated_files = %w( manifest.json )
|
59
|
-
|
59
|
+
|
60
60
|
# OR if you're not hashing the server-bundle.js, then you should include your server-bundle.js in the list.
|
61
61
|
# config.webpack_generated_files = %w( server-bundle.js manifest.json )
|
62
|
-
|
62
|
+
|
63
63
|
# If you are using the ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
|
64
64
|
# with rspec then this controls what yarn command is run
|
65
65
|
# to automatically refresh your webpack assets on every test run.
|
@@ -52,18 +52,28 @@ First be sure to run `rails -v` and check you are using Rails 5.1.3 or above. If
|
|
52
52
|
cd <directory where you want to create your new Rails app>
|
53
53
|
|
54
54
|
# Any name you like for the rails app
|
55
|
-
# Skip javascript so will add that next and get the current version
|
55
|
+
# Skip javascript so will add that next and get the current version
|
56
56
|
rails new --skip-sprockets -J --skip-turbolinks test-react-on-rails-v12-no-sprockets
|
57
57
|
|
58
58
|
cd test-react-on-rails
|
59
59
|
bundle
|
60
60
|
```
|
61
61
|
|
62
|
-
## Add the webpacker
|
62
|
+
## Add the webpacker and react_on_rails gems
|
63
|
+
To avoid issues regarding inconsistent gem and npm versions, you should specify the exact versions
|
64
|
+
of both the gem and npm package. In other words, don't use the `^` or `~` in the version specifications.
|
65
|
+
_Use the latest version for react_on_rails._
|
63
66
|
|
64
67
|
```
|
68
|
+
gem 'react_on_rails', '12.0.4' # prefer exact gem version to match npm version
|
69
|
+
```
|
70
|
+
|
71
|
+
Note: The latest released React On Rails version is considered stable. Please use the latest
|
72
|
+
version to ensure you get all the security patches and the best support.
|
73
|
+
|
74
|
+
```bash
|
65
75
|
bundle add webpacker
|
66
|
-
bundle add react_on_rails
|
76
|
+
bundle add react_on_rails --version=12.0.4 --strict
|
67
77
|
```
|
68
78
|
|
69
79
|
## Run the webpacker generator
|
@@ -82,29 +92,11 @@ git add -A
|
|
82
92
|
git commit -m "Initial commit"
|
83
93
|
```
|
84
94
|
|
85
|
-
##
|
86
|
-
|
87
|
-
To avoid issues regarding inconsistent gem and npm versions, you should specify the exact versions
|
88
|
-
of both the gem and npm package. In other words, don't use the `^` or `~` in the version specifications.
|
89
|
-
|
90
|
-
```
|
91
|
-
gem 'react_on_rails', '12.0.0' # prefer exact gem version to match npm version
|
92
|
-
```
|
93
|
-
|
94
|
-
Note: The latest released React On Rails version is considered stable. Please use the latest
|
95
|
-
version to ensure you get all the security patches and the best support.
|
96
|
-
|
97
|
-
Run `bundle` and commit the changes.
|
98
|
-
|
99
|
-
```
|
100
|
-
bundle
|
101
|
-
|
102
|
-
git commit -am "Added React on Rails Gem"
|
103
|
-
```
|
95
|
+
## Run the React on Rails Generator
|
104
96
|
|
105
97
|
Install React on Rails: `rails generate react_on_rails:install`. You need to first git commit your files before running the generator, or else it will generate an error.
|
106
98
|
|
107
|
-
Note, using `redux` is no longer recommended as the basic installer uses React Hooks.
|
99
|
+
Note, using `redux` is no longer recommended as the basic installer uses React Hooks.
|
108
100
|
If you want the redux install: `rails generate react_on_rails:install --redux`
|
109
101
|
|
110
102
|
```
|
@@ -131,7 +123,7 @@ First, check that the `hmr` and the `inline` options are `true` in your `config/
|
|
131
123
|
|
132
124
|
The basic setup will have HMR working with the default webpacker setup. The basic
|
133
125
|
[HMR](https://webpack.js.org/concepts/hot-module-replacement/), without a special
|
134
|
-
React setup, will cause a full page refresh each time you save a file.
|
126
|
+
React setup, will cause a full page refresh each time you save a file.
|
135
127
|
|
136
128
|
## Deploying to Heroku
|
137
129
|
|
@@ -300,8 +292,8 @@ versus with server rendering:
|
|
300
292
|
|
301
293
|
For more details on server rendering, see:
|
302
294
|
|
303
|
-
+ [Client vs. Server Rendering](
|
304
|
-
+ [React Server Rendering](
|
295
|
+
+ [Client vs. Server Rendering](https://www.shakacode.com/react-on-rails/docs/basics/client-vs-server-rendering)
|
296
|
+
+ [React Server Rendering](https://www.shakacode.com/react-on-rails/docs/basics/react-server-rendering)
|
305
297
|
|
306
298
|
## Moving from the Rails default `/app/javascript` to the recommended `/client` structure
|
307
299
|
|
@@ -328,7 +320,7 @@ When you change a JSX file and save, the browser will automatically refresh!
|
|
328
320
|
|
329
321
|
So you get some basics from HMR with no code changes. If you want to go further, take a look at these links:
|
330
322
|
|
331
|
-
* https://github.com/rails/webpacker/blob/
|
323
|
+
* https://github.com/rails/webpacker/blob/5-x-stable/docs/webpack-dev-server.md
|
332
324
|
* https://webpack.js.org/configuration/dev-server/
|
333
325
|
* https://webpack.js.org/concepts/hot-module-replacement/
|
334
326
|
|
@@ -343,7 +335,7 @@ In case you are running some custom setup with different IP or PORT you should a
|
|
343
335
|
web: rails s -p 8080 -b 0.0.0.0
|
344
336
|
```
|
345
337
|
|
346
|
-
Then visit https://your-shared-addr.c9users.io:8080/hello_world
|
338
|
+
Then visit https://your-shared-addr.c9users.io:8080/hello_world
|
347
339
|
|
348
340
|
## RubyMine
|
349
341
|
|
@@ -357,8 +349,8 @@ It's super important to exclude certain directories from RubyMine or else it wil
|
|
357
349
|
|
358
350
|
## Conclusion
|
359
351
|
|
360
|
-
* Browse the docs
|
352
|
+
* Browse the docs on [our documentation website](https://www.shakacode.com/react-on-rails/docs/)
|
361
353
|
|
362
|
-
Feedback is greatly appreciated! As are stars on github!
|
354
|
+
Feedback is greatly appreciated! As are stars on github!
|
363
355
|
|
364
356
|
If you want personalized help, don't hesitate to get in touch with us at [contact@shakacode.com](mailto:contact@shakacode.com). We offer [React on Rails Pro](https://github.com/shakacode/react_on_rails/wiki) and consulting so you can focus on your app and not on how to make Webpack plus Rails work optimally.
|
@@ -9,7 +9,7 @@ We specialize in helping companies to quickly and efficiently upgrade. The older
|
|
9
9
|
### Recent versions
|
10
10
|
Make sure that you are on a relatively more recent version of rails and webpacker. Yes, the [rails/webpacker](https://github.com/rails/webpacker) gem is required!
|
11
11
|
v12 is tested on Rails 6. It should work on Rails v5. If you're on any older version,
|
12
|
-
and v12 doesn't work, please file an issue.
|
12
|
+
and v12 doesn't work, please file an issue.
|
13
13
|
|
14
14
|
### Removed Configuration config.symlink_non_digested_assets_regex
|
15
15
|
Remove `config.symlink_non_digested_assets_regex` from your `config/initializers/react_on_rails.rb`.
|
@@ -25,7 +25,7 @@ If you still need that feature, please file an issue.
|
|
25
25
|
In order to solve the issues regarding React Hooks compatibility, the number of parameters
|
26
26
|
for functions is used to determine if you have a Render-Function that will get invoked to
|
27
27
|
return a React component, or you are registering a React component defined by a function.
|
28
|
-
Please see [Render-Functions and the Rails Context](
|
28
|
+
Please see [Render-Functions and the Rails Context](https://www.shakacode.com/react-on-rails/docs/basics/render-functions-and-railscontext) for
|
29
29
|
more information on what a Render-Function is.
|
30
30
|
|
31
31
|
##### Update required for registered functions taking exactly 2 params.
|
@@ -35,14 +35,14 @@ Registered Objects are of the following type:
|
|
35
35
|
```js
|
36
36
|
export default (props) => <Component {...props} />;
|
37
37
|
```
|
38
|
-
|
38
|
+
|
39
39
|
2. **Function that takes only zero or one params and you return an Object (_not a React Element_)**. If the function takes zero or one params, **you need to add one or two unused params so you have exactly 2 params** and then that function will be treated as a render function and it can return an Object rather than a React element. If you don't do this, you'll see this obscure error message:
|
40
40
|
|
41
41
|
```
|
42
42
|
[SERVER] message: Objects are not valid as a React child (found: object with keys {renderedHtml}). If you meant to render a collection of children, use an array instead.
|
43
43
|
in YourComponentRenderFunction
|
44
44
|
```
|
45
|
-
|
45
|
+
|
46
46
|
So look in YourComponentRenderFunction and do this change
|
47
47
|
|
48
48
|
```js
|
@@ -50,7 +50,7 @@ Registered Objects are of the following type:
|
|
50
50
|
```
|
51
51
|
|
52
52
|
To have exactly 2 arguments:
|
53
|
-
|
53
|
+
|
54
54
|
```js
|
55
55
|
export default (props, _railsContext) => { renderedHTML: getRenderedHTML };
|
56
56
|
```
|
@@ -65,13 +65,13 @@ Registered Objects are of the following type:
|
|
65
65
|
an Object**, then no migration is required.
|
66
66
|
4. Function that takes **3 params** and uses the 3rd param, `domNodeId`, to call `ReactDOM.hydrate`. If the function takes 3 params, there is **no migration needed** for that function.
|
67
67
|
5. ES6 or ES5 class. There is **no migration needed**.
|
68
|
-
|
68
|
+
|
69
69
|
Previously, with case number 2, you could return a React Element.
|
70
70
|
|
71
71
|
The fix is simple. Here is an example of the change you'll do:
|
72
72
|
|
73
73
|
![2020-07-07_09-43-51 (1)](https://user-images.githubusercontent.com/1118459/86927351-eff79e80-c0ce-11ea-9172-d6855c45e2bb.png)
|
74
|
-
|
74
|
+
|
75
75
|
##### Broken, as this function takes two params and it returns a React Element from a JSX Literal
|
76
76
|
```js
|
77
77
|
export default (props, railsContext) => <Component {{...props, railsContext} />;
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# Webpack Configuration: custom setup for Webpack or rails/webpacker?
|
2
2
|
|
3
|
-
## Webpack vs. rails/webpacker
|
3
|
+
## Webpack vs. rails/webpacker
|
4
4
|
|
5
|
-
[Webpack](https://webpack.js.org) is the JavaScript npm package that prepares all your client-side assets. The Rails asset pipeline used to be the preferable way to prepare client-side assets.
|
5
|
+
[Webpack](https://webpack.js.org) is the JavaScript npm package that prepares all your client-side assets. The Rails asset pipeline used to be the preferable way to prepare client-side assets.
|
6
6
|
|
7
7
|
[rails/webpacker](https://github.com/rails/webpacker) is the Ruby gem that mainly gives us 2 things:
|
8
8
|
|
@@ -22,13 +22,13 @@ A key decision in your use React on Rails is whether you go with the rails/webpa
|
|
22
22
|
|
23
23
|
## Option 1: Default Generator Setup: rails/webpacker app/javascript
|
24
24
|
|
25
|
-
Typical rails/webpacker apps have a standard directory structure as documented [here](https://github.com/rails/webpacker/blob/
|
25
|
+
Typical rails/webpacker apps have a standard directory structure as documented [here](https://github.com/rails/webpacker/blob/5-x-stable/docs/recommended-project-structure.md). If you follow the steps in the the [basic tutorial](https://www.shakacode.com/react-on-rails/docs/basics/tutorial), 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://www.shakacode.com/react-on-rails/docs/javascript/webpack).
|
26
26
|
|
27
27
|
The *advantage* of using rails/webpacker to configure Webpack is that there is very little code needed to get started and you don't need to understand really anything about Webpack customization.
|
28
28
|
|
29
29
|
## Option 2: Traditional React on Rails using the /client directory
|
30
30
|
|
31
|
-
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`.
|
31
|
+
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`.
|
32
32
|
|
33
33
|
You can access values in the `config/webpacker.yml`
|
34
34
|
|
@@ -40,5 +40,3 @@ You will want consider using some of the same values set in these files:
|
|
40
40
|
|
41
41
|
* https://github.com/rails/webpacker/blob/master/package/environments/base.js
|
42
42
|
* https://github.com/rails/webpacker/blob/master/package/environments/development.js
|
43
|
-
|
44
|
-
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Linters
|
2
|
-
These linters support the [ShakaCode Style Guidelines](
|
2
|
+
These linters support the [ShakaCode Style Guidelines](https://www.shakacode.com/react-on-rails/docs/misc/style)
|
3
3
|
|
4
4
|
## Autofix!
|
5
5
|
|
@@ -15,9 +15,9 @@ If you haven't tried the autofix options for `eslint` and `rubocop`, you're seri
|
|
15
15
|
```
|
16
16
|
eslint --fix .
|
17
17
|
```
|
18
|
-
|
19
|
-
or
|
20
|
-
|
18
|
+
|
19
|
+
or
|
20
|
+
|
21
21
|
```
|
22
22
|
npm run lint -- --fix
|
23
23
|
```
|
@@ -32,7 +32,7 @@ Rules are configured with a 0, 1 or 2. Setting a rule to 0 is turning it off, se
|
|
32
32
|
|
33
33
|
Rules can also take a few additional options. In this case, the rule can be set to an array, the first item of which is the 0/1/2 flag and the rest are options.
|
34
34
|
|
35
|
-
See file [.eslintrc](
|
35
|
+
See file [.eslintrc](https://github.com/shakacode/react_on_rails/tree/master/.eslintrc) for examples of configuration
|
36
36
|
|
37
37
|
### Specify/Override rules in code
|
38
38
|
|
@@ -66,4 +66,3 @@ You can disable all rules for a line or block, or only specific rules, as shown
|
|
66
66
|
* [ESLint quick start](http://untilfalse.com/eslint-quick-start/)
|
67
67
|
* [RuboCop](https://github.com/bbatsov/rubocop)
|
68
68
|
* [ESLint](http://eslint.org/)
|
69
|
-
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Pull Requests
|
1
|
+
# Pull Requests
|
2
2
|
|
3
3
|
## Checklist before Committing
|
4
4
|
1. `rake`: runs all linters and specs (you need Docker setup, see below)
|
@@ -36,9 +36,7 @@ When making doc changes, we want the change to work on both the gitbook and the
|
|
36
36
|
|
37
37
|
### Links to other docs:
|
38
38
|
* When making references to doc files, use a relative URL path like:
|
39
|
-
`[Installation Overview](docs/
|
39
|
+
`[Installation Overview](https://www.shakacode.com/react-on-rails/docs/additional-details/manual-installation-overview)`
|
40
40
|
|
41
41
|
* When making references to source code files, use a full url path like:
|
42
42
|
`[spec/dummy/config/initializers/react_on_rails.rb](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/config/initializers/react_on_rails.rb)`
|
43
|
-
|
44
|
-
|
@@ -3,7 +3,7 @@
|
|
3
3
|
We're now releasing this as a combined ruby gem plus npm package. We will keep the version numbers in sync.
|
4
4
|
|
5
5
|
## Testing the Gem before Release from a Rails App
|
6
|
-
See [Contributing](
|
6
|
+
See [Contributing](https://github.com/shakacode/react_on_rails/tree/master/CONTRIBUTING.md)
|
7
7
|
|
8
8
|
## Releasing a new gem version
|
9
9
|
Run `rake -D release` to see instructions on how to release via the rake task.
|
File without changes
|
File without changes
|
data/docs/home.md
ADDED
@@ -0,0 +1,382 @@
|
|
1
|
+
# React on Rails
|
2
|
+
|
3
|
+
*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).*
|
4
|
+
|
5
|
+
**If you're viewing this page on Github, please go to [our documentation website](https://www.shakacode.com/react-on-rails/docs/) instead!**
|
6
|
+
|
7
|
+
#### News
|
8
|
+
**October 14, 2020**: [RUBY ROGUES
|
9
|
+
RR 474: React on Rails V12 – Don’t Shave That Yak! with Justin Gordon](https://devchat.tv/ruby-rogues/rr-474-react-on-rails-v12-dont-shave-that-yak-with-justin-gordon/).
|
10
|
+
|
11
|
+
**October 1, 2020**: See the [spec/dummy](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy) example repo for a simple configuration of webpack via the rails/webpacker gem
|
12
|
+
that supports SSR.
|
13
|
+
|
14
|
+
**August 2, 2020**: See the example repo of [React on Rails Tutorial With SSR, HMR fast refresh, and TypeScript](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh) for a new way to setup the creation of your SSR bundle with `rails/webpacker`.
|
15
|
+
|
16
|
+
**July 8, 2020**: Release v12 of React on Rails.
|
17
|
+
|
18
|
+
**Major Improvements**
|
19
|
+
|
20
|
+
1. **React Hooks Support** for top level components
|
21
|
+
2. **Typescript bindings**
|
22
|
+
3. **rails/webpacker** "just works" with React on Rails by default.
|
23
|
+
4. i18n support for generating a JSON file rather than a JS file.
|
24
|
+
|
25
|
+
Be sure to see the [CHANGELOG.md](https://github.com/shakacode/react_on_rails/tree/master/CHANGELOG.md) and read the upgrade instructions:
|
26
|
+
[docs/basics/upgrading-react-on-rails](https://www.shakacode.com/react-on-rails/docs/basics/upgrading-react-on-rails#upgrading-to-v12).
|
27
|
+
|
28
|
+
* See Justin's RailsConf talk: [Webpacker, It-Just-Works, But How?](http://railsconf.com/2020/video/justin-gordon-webpacker-it-just-works-but-how).
|
29
|
+
* Are you interested in support for React on Rails? Do you want to use Node.js to do your server-side rendering so libraries like Emotion and Loadable Components just work, as compared to rendering via Ruby embedded JS? If so check out [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro).
|
30
|
+
* 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.
|
31
|
+
---
|
32
|
+
|
33
|
+
#### About
|
34
|
+
React on Rails integrates Rails with (server rendering of) Facebook's [React](https://github.com/facebook/react) front-end framework.
|
35
|
+
|
36
|
+
This project is maintained by the software consulting firm [ShakaCode](https://www.shakacode.com). We focus on Ruby on Rails applications with React front-ends, often using TypeScript or ReasonML. We also build Gatsby sites. See [our recent work](https://www.shakacode.com/recent-work) for examples of what we do.
|
37
|
+
|
38
|
+
Interested in optimizing your webpack setup for React on Rails including code
|
39
|
+
splitting with [react-router](https://github.com/ReactTraining/react-router#readme),
|
40
|
+
and [loadable-components](https://loadable-components.com/) with server-side rendering?
|
41
|
+
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/).
|
42
|
+
|
43
|
+
Feel free to contact Justin Gordon, [justin@shakacode.com](mailto:justin@shakacode.com), maintainer of React on Rails, for more information.
|
44
|
+
|
45
|
+
[Click to join **React + Rails Slack**](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE).
|
46
|
+
|
47
|
+
# Intro
|
48
|
+
|
49
|
+
## Project Objective
|
50
|
+
|
51
|
+
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.
|
52
|
+
|
53
|
+
## Features and Why React on Rails?
|
54
|
+
|
55
|
+
Given that `rails/webpacker` gem already provides basic React integration, why would you use "React on Rails"?
|
56
|
+
|
57
|
+
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.
|
58
|
+
1. Tight integration with [rails/webpacker](https://github.com/rails/webpacker).
|
59
|
+
1. Server-Side Rendering (SSR), often used for SEO crawler indexing and UX performance, is not offered by `rails/webpacker`.
|
60
|
+
1. [Redux](https://github.com/reactjs/redux) and [React Router](https://github.com/ReactTraining/react-router#readme) integration with server-side-rendering.
|
61
|
+
1. [Internationalization (I18n) and (localization)](https://www.shakacode.com/react-on-rails/docs/basics/i18n)
|
62
|
+
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+depth%3Aall/).
|
63
|
+
1. [Reason ML Support](https://github.com/shakacode/reason-react-on-rails-example).
|
64
|
+
|
65
|
+
See the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) for an example of a live implementation and code.
|
66
|
+
|
67
|
+
## ShakaCode Forum Premium Content
|
68
|
+
_Requires creating a free account._
|
69
|
+
|
70
|
+
* [How to use different versions of a file for client and server rendering](https://forum.shakacode.com/t/how-to-use-different-versions-of-a-file-for-client-and-server-rendering/1352)
|
71
|
+
|
72
|
+
----
|
73
|
+
|
74
|
+
# Docs
|
75
|
+
|
76
|
+
**Consider browsing this on our [website](https://www.shakacode.com/react-on-rails/docs/).**
|
77
|
+
|
78
|
+
## Prerequisites
|
79
|
+
|
80
|
+
Ruby on Rails >=5 and rails/webpacker 4.2+.
|
81
|
+
|
82
|
+
## Getting Started
|
83
|
+
|
84
|
+
Note, the best way to understand how to use ReactOnRails is to study a few simple examples. You can do a quick demo setup, either on your existing app or on a new Rails app.
|
85
|
+
|
86
|
+
1. Do the quick [tutorial](https://www.shakacode.com/react-on-rails/docs/basics/tutorial).
|
87
|
+
2. Add React on Rails to an existing Rails app per [the instructions](https://www.shakacode.com/react-on-rails/docs/basics/installation-into-an-existing-rails-app).
|
88
|
+
3. Look at [spec/dummy](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy), a simple, no DB example.
|
89
|
+
3. Look at [github.com/shakacode/react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial); it's a full-featured example live at [www.reactrails.com](http://www.reactrails.com).
|
90
|
+
|
91
|
+
## Basic Installation
|
92
|
+
|
93
|
+
*See also [the instructions for installing into an existing Rails app](https://www.shakacode.com/react-on-rails/docs/basics/installation-into-an-existing-rails-app).*
|
94
|
+
|
95
|
+
2. Add the `react_on_rails` gem to Gemfile:
|
96
|
+
|
97
|
+
```bash
|
98
|
+
bundle add react_on_rails --strict
|
99
|
+
```
|
100
|
+
|
101
|
+
4. Commit this to git (or else you cannot run the generator unless you pass the option `--ignore-warnings`).
|
102
|
+
|
103
|
+
5. Run the generator:
|
104
|
+
|
105
|
+
```bash
|
106
|
+
rails generate react_on_rails:install
|
107
|
+
```
|
108
|
+
|
109
|
+
6. Start the app:
|
110
|
+
|
111
|
+
```bash
|
112
|
+
rails s
|
113
|
+
```
|
114
|
+
|
115
|
+
7. Visit http://localhost:3000/hello_world.
|
116
|
+
|
117
|
+
|
118
|
+
### Turning on server rendering
|
119
|
+
|
120
|
+
With the code from running the React on Rails generator above:
|
121
|
+
|
122
|
+
1. Edit `app/views/hello_world/index.html.erb` and set `prerender` to `true`.
|
123
|
+
2. Refresh the page.
|
124
|
+
|
125
|
+
Below is the line where you turn server rendering on by setting `prerender` to true:
|
126
|
+
|
127
|
+
```erb
|
128
|
+
<%= react_component("HelloWorld", props: @hello_world_props, prerender: false) %>
|
129
|
+
```
|
130
|
+
|
131
|
+
Note, if you got an error in your console regarding "ReferenceError: window is not defined",
|
132
|
+
then you need to edit `config/webpacker.yml` and set `hmr: false` and `inline: false`.
|
133
|
+
See [rails/webpacker PR 2644](https://github.com/rails/webpacker/pull/2644) for a fix for this
|
134
|
+
issue.
|
135
|
+
|
136
|
+
## Basic Usage
|
137
|
+
|
138
|
+
### Configuration
|
139
|
+
|
140
|
+
* Configure `config/initializers/react_on_rails.rb`. You can adjust some necessary settings and defaults. See file [docs/basics/configuration.md](https://www.shakacode.com/react-on-rails/docs/basics/configuration) for documentation of all configuration options.
|
141
|
+
* 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](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/config/webpacker.yml) example or the official default [webpacker.yml](https://github.com/rails/webpacker/blob/master/lib/install/config/webpacker.yml).
|
142
|
+
* 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.
|
143
|
+
* Your `public_output_path` must match your custom Webpack configuration for `output` of your bundles.
|
144
|
+
* Only set `cache_manifest` to `true` in your production env.
|
145
|
+
|
146
|
+
## Including your React Component on your Rails Views
|
147
|
+
|
148
|
+
- React component are rendered via your Rails Views. Here's an ERB sample:
|
149
|
+
|
150
|
+
```erb
|
151
|
+
<%= react_component("HelloWorld", props: @some_props) %>
|
152
|
+
```
|
153
|
+
|
154
|
+
- **Server-Side Rendering**: Your react component is first rendered into HTML on the server. Use the **prerender** option:
|
155
|
+
|
156
|
+
```erb
|
157
|
+
<%= react_component("HelloWorld", props: @some_props, prerender: true) %>
|
158
|
+
```
|
159
|
+
|
160
|
+
- The `component_name` parameter is a string matching the name you used to expose your React component globally. So, in the above examples, if you had a React component named "HelloWorld", you would register it with the following lines:
|
161
|
+
|
162
|
+
```js
|
163
|
+
import ReactOnRails from 'react-on-rails';
|
164
|
+
import HelloWorld from './HelloWorld';
|
165
|
+
ReactOnRails.register({ HelloWorld });
|
166
|
+
```
|
167
|
+
|
168
|
+
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.
|
169
|
+
|
170
|
+
- `@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:
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
# Rails View
|
174
|
+
<%= react_component("HelloWorld", props: { name: "Stranger" }) %>
|
175
|
+
```
|
176
|
+
|
177
|
+
- 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](https://www.shakacode.com/react-on-rails/docs/basics/render-functions-and-railscontext) for more details on this topic.
|
178
|
+
|
179
|
+
```js
|
180
|
+
import React from 'react';
|
181
|
+
|
182
|
+
export default (props, railsContext) => {
|
183
|
+
// Note wrap in a function to make this a React function component
|
184
|
+
return () => (
|
185
|
+
<div>
|
186
|
+
Your locale is {railsContext.i18nLocale}.<br/>
|
187
|
+
Hello, {props.name}!
|
188
|
+
</div>
|
189
|
+
);
|
190
|
+
};
|
191
|
+
```
|
192
|
+
|
193
|
+
See the [View Helpers API](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api) for more details on `react_component` and its sibling function `react_component_hash`.
|
194
|
+
|
195
|
+
## Globally Exposing Your React Components
|
196
|
+
|
197
|
+
For the React on Rails view helper `react_component` to use your React components, you will have to **register** them in your JavaScript code.
|
198
|
+
|
199
|
+
Use modules just as you would when using Webpack and React without Rails. The difference is that instead of mounting React components directly to an element using `React.render`, you **register your components to ReactOnRails and then mount them with helpers inside of your Rails views**.
|
200
|
+
|
201
|
+
This is how to expose a component to the `react_component` view helper.
|
202
|
+
|
203
|
+
```javascript
|
204
|
+
// app/javascript/packs/hello-world-bundle.js
|
205
|
+
import HelloWorld from '../components/HelloWorld';
|
206
|
+
import ReactOnRails from 'react-on-rails';
|
207
|
+
ReactOnRails.register({ HelloWorld });
|
208
|
+
```
|
209
|
+
|
210
|
+
#### Different Server-Side Rendering Code (and a Server-Specific Bundle)
|
211
|
+
|
212
|
+
You may want different code for your server-rendered components running server side versus client side. For example, if you have an animation that runs when a component is displayed, you might need to turn that off when server rendering. One way to handle this is conditional code like `if (window) { doClientOnlyCode() }`.
|
213
|
+
|
214
|
+
Another way is to use a separate webpack configuration file that can use a different server side entry file, like 'serverRegistration.js' as opposed to 'clientRegistration.js.' That would set up different code for server rendering.
|
215
|
+
|
216
|
+
For details on techniques to use different code for client and server rendering, see: [How to use different versions of a file for client and server rendering](https://forum.shakacode.com/t/how-to-use-different-versions-of-a-file-for-client-and-server-rendering/1352). (_Requires creating a free account._)
|
217
|
+
|
218
|
+
## Specifying Your React Components: Register directly or use render-functions
|
219
|
+
|
220
|
+
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:
|
221
|
+
|
222
|
+
1. You to have access to the `railsContext`. See [documentation for the railsContext](https://www.shakacode.com/react-on-rails/docs/basics/render-functions-and-railscontext) in terms of why you might need it. You **need** a Render-Function to access the `railsContext`.
|
223
|
+
2. You can use the passed-in props to initialize a redux store or set up react-router.
|
224
|
+
3. You can return different components depending on what's in the props.
|
225
|
+
|
226
|
+
Note, the return value of a **Render-Function** should be either a React Function or Class Component, or an object representing server rendering results.
|
227
|
+
|
228
|
+
Do not return a React Element (JSX).
|
229
|
+
|
230
|
+
ReactOnRails will automatically detect a registered Render-Function by the fact that the function takes
|
231
|
+
more than 1 parameter. In other words, if you want the ability to provide a function that returns the
|
232
|
+
React component, then you need to specify at least a second parameter. This is the `railsContext`.
|
233
|
+
If you're not using this parameter, declare your function with the unused param:
|
234
|
+
|
235
|
+
```js
|
236
|
+
const MyComponentGenerator = (props, _railsContext) => {
|
237
|
+
if (props.print) {
|
238
|
+
// This is a React FunctionComponent because it is wrapped in a function.
|
239
|
+
return () => <H1>{JSON.stringify(props)}</H1>;
|
240
|
+
}
|
241
|
+
}
|
242
|
+
```
|
243
|
+
|
244
|
+
Thus, there is no difference between registering a React Function Component or class Component versus a "Render-Function." Just call `ReactOnRails.register`.
|
245
|
+
|
246
|
+
## react_component_hash for Render-Functions
|
247
|
+
|
248
|
+
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`.
|
249
|
+
|
250
|
+
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:
|
251
|
+
|
252
|
+
```js
|
253
|
+
{ renderedHtml: { componentHtml, customKey1, customKey2} }
|
254
|
+
```
|
255
|
+
|
256
|
+
For details on using react_component_hash with react-helmet, see [our react-helmet documentation](https://www.shakacode.com/react-on-rails/docs/additional-reading/react-helmet).
|
257
|
+
|
258
|
+
## Error Handling
|
259
|
+
|
260
|
+
* All errors from ReactOnRails will be of type ReactOnRails::Error.
|
261
|
+
* Prerendering (server rendering) errors get context information for HoneyBadger and Sentry for easier debugging.
|
262
|
+
|
263
|
+
## I18n
|
264
|
+
|
265
|
+
React on Rails provides an option for automatic conversions of Rails `*.yml` locale files into `*.json` or `*.js*.
|
266
|
+
See the [How to add I18n](https://www.shakacode.com/react-on-rails/docs/basics/i18n) for a summary of adding I18n.
|
267
|
+
|
268
|
+
## More Details
|
269
|
+
|
270
|
+
Browse the links in the [Summary Table of Contents](https://github.com/shakacode/react_on_rails/tree/master/SUMMARY.md)
|
271
|
+
|
272
|
+
Here are some highly recommended next articles to read:
|
273
|
+
|
274
|
+
1. [How React on Rails Works](https://www.shakacode.com/react-on-rails/docs/basics/how-react-on-rails-works)
|
275
|
+
1. [Webpack Configuration](https://www.shakacode.com/react-on-rails/docs/basics/webpack-configuration)
|
276
|
+
1. [View Helpers API](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api)
|
277
|
+
1. [Caching and Performance: React on Rails Pro](https://www.shakacode.com/react-on-rails-pro).
|
278
|
+
1. [Deployment](https://www.shakacode.com/react-on-rails/docs/basics/deployment).
|
279
|
+
|
280
|
+
# Support
|
281
|
+
|
282
|
+
[Click to join **React + Rails Slack**](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE).
|
283
|
+
|
284
|
+
## Community Resources
|
285
|
+
|
286
|
+
Please [**click to subscribe**](https://app.mailerlite.com/webforms/landing/l1d9x5) to keep in touch with Justin Gordon and [ShakaCode](http://www.shakacode.com/). I intend to send announcements of new releases of React on Rails and of our latest [blog articles](https://blog.shakacode.com) and tutorials.
|
287
|
+
|
288
|
+
[![2017-01-31_14-16-56](https://cloud.githubusercontent.com/assets/1118459/22490211/f7a70418-e7bf-11e6-9bef-b3ccd715dbf8.png)](https://app.mailerlite.com/webforms/landing/l1d9x5)
|
289
|
+
|
290
|
+
- **Slack Room**: [Contact us](mailto:contact@shakacode.com) for an invite to the ShakaCode Slack room! Let us know if you want to contribute.
|
291
|
+
- **[forum.shakacode.com](https://forum.shakacode.com)**: Post your questions
|
292
|
+
- **[@railsonmaui on Twitter](https://twitter.com/railsonmaui)**
|
293
|
+
- For a live, [open source](https://github.com/shakacode/react-webpack-rails-tutorial), example of this gem, see [www.reactrails.com](http://www.reactrails.com).
|
294
|
+
- See [Projects](https://github.com/shakacode/react_on_rails/tree/master/PROJECTS.md) using and [KUDOS](https://github.com/shakacode/react_on_rails/tree/master/KUDOS.md) for React on Rails. Please submit yours! Please edit either page or [email us](mailto:contact@shakacode.com) and we'll add your info. We also **love stars** as it helps us attract new users and contributors.
|
295
|
+
- *See [NEWS.md](https://github.com/shakacode/react_on_rails/tree/master/NEWS.md) for more notes over time.*
|
296
|
+
|
297
|
+
## Contributing
|
298
|
+
|
299
|
+
Bug reports and pull requests are welcome. See [Contributing](https://github.com/shakacode/react_on_rails/tree/master/CONTRIBUTING.md) to get started, and the [list of help wanted issues](https://github.com/shakacode/react_on_rails/labels/contributions%3A%20up%20for%20grabs%21).
|
300
|
+
|
301
|
+
## React on Rails Pro
|
302
|
+
|
303
|
+
React on Rails Pro provides Node server rendering, fragment caching, code-splitting, and other performance enhancements for React on Rails. For a case study, see the article [HVMN’s 90% Reduction in Server Response Time from React on Rails Pro](https://blog.shakacode.com/hvmns-90-reduction-in-server-response-time-from-react-on-rails-pro-eb08226687db). The [Wiki](https://github.com/shakacode/react_on_rails/wiki) contains more details.
|
304
|
+
|
305
|
+
[![2018-09-11_10-31-11](https://user-images.githubusercontent.com/1118459/45467845-5bcc7400-b6bd-11e8-91e1-e0cf806d4ea4.png)](https://blog.shakacode.com/hvmns-90-reduction-in-server-response-time-from-react-on-rails-pro-eb08226687db)
|
306
|
+
|
307
|
+
## React on Rails Pro Support
|
308
|
+
|
309
|
+
The [React on Rails Pro Support Plan](https://www.shakacode.com/react-on-rails-pro) can help!
|
310
|
+
|
311
|
+
* Optimizing your webpack setup to the latest Webpack for React on Rails including code splitting with loadable-components.
|
312
|
+
* Upgrading your app to use the current `rails/webpacker` setup that skips the Sprockets asset pipeline.
|
313
|
+
* Better performance client and server side.
|
314
|
+
* Best practices based on over 6 years of React on Rails experience on many production projects.
|
315
|
+
* Using [Reason](https://reasonml.github.io/) with (or without) React on Rails.
|
316
|
+
|
317
|
+
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!
|
318
|
+
|
319
|
+
Please email Justin Gordon [justin@shakacode.com](mailto:justin@shakacode.com), the maintainer of React on Rails, for more information.
|
320
|
+
|
321
|
+
### Fragment Caching
|
322
|
+
|
323
|
+
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:
|
324
|
+
|
325
|
+
1. The `cache_key` takes the same parameters as any Rails `cache` view helper.
|
326
|
+
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`:
|
327
|
+
|
328
|
+
```ruby
|
329
|
+
<%= cached_react_component("App", cache_key: [@user, @post], prerender: true) do
|
330
|
+
some_slow_method_that_returns_props
|
331
|
+
end %>
|
332
|
+
```
|
333
|
+
|
334
|
+
Such fragment caching saves CPU work for your web server and greatly reduces the request time. It completely skips the evaluation costs of:
|
335
|
+
|
336
|
+
1. Database calls to compute the props.
|
337
|
+
2. Serialization the props values hash into a JSON string for evaluating JavaScript to server render.
|
338
|
+
3. Costs associated with evaluating JavaScript from your Ruby code.
|
339
|
+
4. Creating the HTML string containing the props and the server-rendered JavaScript code.
|
340
|
+
|
341
|
+
Note, even without server rendering (without step 3 above), fragment caching is still effective.
|
342
|
+
|
343
|
+
## Integration with Node.js for Server Rendering
|
344
|
+
|
345
|
+
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).
|
346
|
+
|
347
|
+
## Testimonials for ShakaCode
|
348
|
+
[HVMN Testimonial, by Paul Benigeri, October 12, 2018](https://www.shakacode.com/react-on-rails/docs/testimonials/hvmn)
|
349
|
+
> 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.
|
350
|
+
|
351
|
+
[ResortPass Testimonial, by Leora Juster, December 10, 2018](https://www.shakacode.com/react-on-rails/docs/testimonials/resortpass)
|
352
|
+
|
353
|
+
> Justin and his team were instrumental in assisting us in setting design foundations and standards for our transition to a react on rails application. Just three months of work with the team at Shaka code and we have a main page of our application server-side rendering at exponentially improved speeds.
|
354
|
+
|
355
|
+
From Joel Hooks, Co-Founder, Chief Nerd at [egghead.io](https://egghead.io/), January 30, 2017:
|
356
|
+
|
357
|
+
![2017-01-30_11-33-59](https://cloud.githubusercontent.com/assets/1118459/22443635/b3549fb4-e6e3-11e6-8ea2-6f589dc93ed3.png)
|
358
|
+
|
359
|
+
For more testimonials, see [Live Projects](https://github.com/shakacode/react_on_rails/tree/master/PROJECTS.md) and [Kudos](https://github.com/shakacode/react_on_rails/tree/master/KUDOS.md).
|
360
|
+
|
361
|
+
# Supporters
|
362
|
+
|
363
|
+
The following companies support this open source project, and ShakaCode uses their products! Justin writes React on Rails on [RubyMine](https://www.jetbrains.com/ruby/). We use [Scout](https://scoutapp.com/) to monitor the live performance of [HawaiiChee.com](https://www.hawaiichee.com), [BrowserStack](https://www.browserstack.com) to solve problems with oddball browsers, and [CodersRank](https://codersrank.io/) to find candidates for our team.
|
364
|
+
|
365
|
+
[![2019-09-24_17-48-00](https://user-images.githubusercontent.com/1118459/65567887-96353780-def3-11e9-926d-4a55e2e186ff.png)](https://www.jetbrains.com/ruby/)
|
366
|
+
[![Scout](https://user-images.githubusercontent.com/1118459/41828269-106b40f8-77d0-11e8-8d19-9c4b167ef9d8.png)](https://scoutapp.com/)
|
367
|
+
[![BrowserStack](https://cloud.githubusercontent.com/assets/1118459/23203304/1261e468-f886-11e6-819e-93b1a3f17da4.png)](https://www.browserstack.com)
|
368
|
+
[![CodersRank](https://user-images.githubusercontent.com/1118459/55040254-ad8a7b00-4fcb-11e9-8936-c6765eb30698.png)](https://codersrank.io/?utm_source=github&utm_medium=banner&utm_campaign=shakacode)
|
369
|
+
|
370
|
+
## Clubhouse
|
371
|
+
I've just moved ShakaCode's development to [ClubHouse](https://clubhouse.io/) from Trello. We're going to be doing this with all our projects. If you want to **try ClubHouse and get 2 months free beyond the 14-day trial period**, click [here to use ShakaCode's referral code](http://r.clbh.se/mvfoNeH). We're participating in their awesome triple-sided referral program, which you can read about [here](https://clubhouse.io/blog/clubhouse-referral-program-5f614bb437c3). By using our [referral code](http://r.clbh.se/mvfoNeH) you'll be supporting ShakaCode and, thus, React on Rails!
|
372
|
+
|
373
|
+
*If you'd like to support React on Rails and have your company listed here, [get in touch](mailto:justin@shakacode.com).*
|
374
|
+
|
375
|
+
Aloha and best wishes from Justin and the ShakaCode team!
|
376
|
+
|
377
|
+
# Work with Us
|
378
|
+
ShakaCode is **[currently looking to hire](http://www.shakacode.com/about/#work-with-us)** like-minded, remote-first, developers that wish to work on our projects, including [Hawaii Chee](https://www.hawaiichee.com). Your main coding interview will be pairing with us on our open source! We're also using [ReasonML](https://reasonml.github.io/) extensively!
|
379
|
+
|
380
|
+
# License
|
381
|
+
|
382
|
+
The gem is available as open source under the terms of the [MIT License](https://github.com/shakacode/react_on_rails/tree/master/LICENSE.md).
|