react_on_rails 12.0.5.beta.0 → 12.1.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 +11 -1
- data/.eslintrc +2 -0
- data/.prettierrc +0 -3
- data/.rubocop.yml +38 -1
- data/CHANGELOG.md +22 -13
- data/CONTRIBUTING.md +3 -2
- data/Gemfile.development_dependencies +3 -2
- data/README.md +68 -65
- 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 +42 -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 +2 -2
- data/docs/basics/react-server-rendering.md +3 -3
- data/docs/basics/rspec-configuration.md +10 -10
- data/docs/{tutorial.md → basics/tutorial.md} +9 -9
- 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 +0 -0
- data/docs/testimonials/testimonials.md +6 -6
- 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/{features → system}/hello_world_spec.rb +2 -2
- data/lib/react_on_rails/helper.rb +5 -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 +19 -3
- data/rakelib/task_helpers.rb +15 -2
- data/yarn.lock +2272 -4960
- metadata +41 -38
- data/docs/additional-reading/upgrade-webpacker-v3-to-v4.md +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ff3b26eb01a206fc2f0a4e3a623463d88a4216c95a36c90b2fa55c5717a308c
|
4
|
+
data.tar.gz: 28b373978a8eb7502c018e03aeec17058ba65d6ced76a50aa932894c76f835df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccb1f3c3d34b9ddbca43e8fe349a2cb3ee27892a1b52d9fe938070f2947ed402fef03d7328041f4f02a7d0b5401b90cdcdc1141230d96efd2ced6da2bc0668b7
|
7
|
+
data.tar.gz: 488f77190eee0fb0ca008535d7fbb8f5a43c380c31c9d4bdacf8d563383a0dc87b0e643eafde37a7d9ffc36e093d8a648c3c95f6b238bf567dcf76caf078027b
|
data/.circleci/config.yml
CHANGED
@@ -31,9 +31,9 @@ aliases:
|
|
31
31
|
- &install-package-node-modules
|
32
32
|
name: Install Node modules with Yarn for renderer package
|
33
33
|
command: |
|
34
|
+
sudo yarn global add yalc
|
34
35
|
yarn install --no-progress --no-emoji
|
35
36
|
yarn run eslint -v
|
36
|
-
sudo yarn global add yalc
|
37
37
|
|
38
38
|
# Install/update Node modules for dummy app unless existing set of modules is satisfying Yarn.
|
39
39
|
- &install-dummy-app-node-modules
|
@@ -274,6 +274,16 @@ jobs:
|
|
274
274
|
# TODO -- need to leverage Circle CI containers
|
275
275
|
command: |
|
276
276
|
bundle exec rake run_rspec:all_dummy
|
277
|
+
# The following step will run only if the main job is finished successfully.
|
278
|
+
# Build hook is triggered by curl command described here https://docs.netlify.com/configure-builds/build-hooks/
|
279
|
+
# NETLIFY_HOOK is an environment variable on CircleCI to keep sensitive data outside the repo
|
280
|
+
- run:
|
281
|
+
name: Deploy SC website
|
282
|
+
command: |
|
283
|
+
if [ $CIRCLE_BRANCH = "master" ]; then
|
284
|
+
curl -X POST -d '{}' ${NETLIFY_HOOK}
|
285
|
+
fi
|
286
|
+
when: on_success
|
277
287
|
- store_test_results:
|
278
288
|
path: ~/rspec
|
279
289
|
- store_artifacts:
|
data/.eslintrc
CHANGED
data/.prettierrc
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# This is the configuration used to check the rubocop source code.
|
2
2
|
# Check out: https://github.com/bbatsov/rubocop
|
3
|
-
require:
|
3
|
+
require:
|
4
|
+
- rubocop-performance
|
5
|
+
- rubocop-rspec
|
4
6
|
|
5
7
|
AllCops:
|
6
8
|
NewCops: enable
|
@@ -87,6 +89,41 @@ Metrics/ModuleLength:
|
|
87
89
|
Naming/RescuedExceptionsVariableName:
|
88
90
|
Enabled: false
|
89
91
|
|
92
|
+
RSpec/AnyInstance:
|
93
|
+
Exclude:
|
94
|
+
- 'spec/react_on_rails/git_utils_spec.rb'
|
95
|
+
- 'spec/react_on_rails/locales_to_js_spec.rb'
|
96
|
+
|
97
|
+
RSpec/DescribeClass:
|
98
|
+
Enabled: false
|
99
|
+
|
100
|
+
RSpec/ExampleLength:
|
101
|
+
Enabled: false
|
102
|
+
|
103
|
+
RSpec/MessageSpies:
|
104
|
+
Enabled: false
|
105
|
+
|
106
|
+
RSpec/NestedGroups:
|
107
|
+
Max: 4
|
108
|
+
|
109
|
+
RSpec/BeforeAfterAll:
|
110
|
+
Exclude:
|
111
|
+
- 'spec/react_on_rails/generators/dev_tests_generator_spec.rb'
|
112
|
+
- 'spec/react_on_rails/generators/install_generator_spec.rb'
|
113
|
+
|
114
|
+
RSpec/MessageChain:
|
115
|
+
Enabled: false
|
116
|
+
|
117
|
+
RSpec/MultipleExpectations:
|
118
|
+
Enabled: false
|
119
|
+
|
120
|
+
RSpec/MultipleDescribes:
|
121
|
+
Exclude:
|
122
|
+
- 'spec/dummy/spec/system/integration_spec.rb'
|
123
|
+
|
124
|
+
RSpec/MultipleMemoizedHelpers:
|
125
|
+
Max: 12
|
126
|
+
|
90
127
|
Style/GlobalVars:
|
91
128
|
Exclude:
|
92
129
|
- 'spec/dummy/config/environments/development.rb'
|
data/CHANGELOG.md
CHANGED
@@ -16,9 +16,17 @@ Please follow the recommendations outlined at [keepachangelog.com](http://keepac
|
|
16
16
|
Changes since last non-beta release.
|
17
17
|
|
18
18
|
*Please add entries here for your pull requests that are not yet released.*
|
19
|
+
|
20
|
+
### [12.1.0] - 2021-03-23
|
21
|
+
#### Added
|
22
|
+
- Added the ability to assign a module with a `call` method to `config.build_production_command`. See [the configuration docs](./docs/basics/configuration.md). [PR 1362: Accept custom module for config.build_production_command](https://github.com/shakacode/react_on_rails/pull/1362).
|
23
|
+
|
24
|
+
#### Fixed
|
25
|
+
- Stop setting NODE_ENV value during precompile, as it interferred with rails/webpacker's setting of NODE_ENV to production by default. Fixes [#1334](https://github.com/shakacode/react_on_rails/issues/1334). [PR 1356: Don't set NODE_ENV in assets.rake](https://github.com/shakacode/react_on_rails/pull/1356) by [alexrozanski](https://github.com/alexrozanski).
|
26
|
+
|
19
27
|
### [12.0.4] - 2020-11-14
|
20
28
|
#### Fixed
|
21
|
-
- Install generator now specifies the version. Fixes [React on Rails Generator installs the older npm package #1336](https://github.com/shakacode/react_on_rails/issues/1336). [PR 1338Fix Generator to use Exact NPM Version](https://github.com/shakacode/react_on_rails/pull/1338) by
|
29
|
+
- Install generator now specifies the version. Fixes [React on Rails Generator installs the older npm package #1336](https://github.com/shakacode/react_on_rails/issues/1336). [PR 1338Fix Generator to use Exact NPM Version](https://github.com/shakacode/react_on_rails/pull/1338) by [justin808](https://github.com/justin808).
|
22
30
|
|
23
31
|
### [12.0.3] - 2020-09-20
|
24
32
|
#### Fixed
|
@@ -30,7 +38,7 @@ Changes since last non-beta release.
|
|
30
38
|
|
31
39
|
### [12.0.2] - 2020-07-09
|
32
40
|
#### Fixed
|
33
|
-
- Remove dependency upon Redux for Typescript types. [PR 1323](https://github.com/shakacode/react_on_rails/pull/1306) by [justin808](https://github.com/justin808).
|
41
|
+
- Remove dependency upon Redux for Typescript types. [PR 1323](https://github.com/shakacode/react_on_rails/pull/1306) by [justin808](https://github.com/justin808).
|
34
42
|
|
35
43
|
### [12.0.1] - 2020-07-09
|
36
44
|
#### Fixed
|
@@ -56,8 +64,8 @@ invoked to return the React component. In that case, you won't need to pass any
|
|
56
64
|
See [docs/basics/upgrading-react-on-rails](./docs/basics/upgrading-react-on-rails.md#upgrading-to-v12)
|
57
65
|
for details.
|
58
66
|
|
59
|
-
#### Other Updates
|
60
|
-
* `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.
|
67
|
+
#### Other Updates
|
68
|
+
* `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.
|
61
69
|
* Changed the precompile task to use the rails/webpacker one by default
|
62
70
|
* Updated generators to use React hooks
|
63
71
|
* Requires the use of rails/webpacker view helpers
|
@@ -72,19 +80,19 @@ for details.
|
|
72
80
|
* Added configuration option `same_bundle_for_client_and_server` with default `false` because
|
73
81
|
|
74
82
|
1. Production applications would typically have a server bundle that differs from the client bundle
|
75
|
-
2. This change only affects trying to use HMR with react_on_rails with rails/webpacker.
|
76
|
-
|
77
|
-
The previous behavior was to always go to the webpack-dev-server for the server bundle if the
|
78
|
-
webpack-dev-server was running _and_ the server bundle was found in the `manifest.json`.
|
79
|
-
|
83
|
+
2. This change only affects trying to use HMR with react_on_rails with rails/webpacker.
|
84
|
+
|
85
|
+
The previous behavior was to always go to the webpack-dev-server for the server bundle if the
|
86
|
+
webpack-dev-server was running _and_ the server bundle was found in the `manifest.json`.
|
87
|
+
|
80
88
|
If you are using the **same bundle for client and server rendering**, then set this configuration option
|
81
89
|
to `true`. By [justin808](https://github.com/shakacode/react_on_rails/pull/1240).
|
82
|
-
|
90
|
+
|
83
91
|
* Added support to export locales in JSON format. New option added `i18n_output_format` which allows to
|
84
92
|
specify locales format either `JSON` or `JS`. **`JSON` format is now the default.**
|
85
|
-
|
93
|
+
|
86
94
|
**Use this config setting to get the old behavior: config.i18n_output_format = 'js'**
|
87
|
-
|
95
|
+
|
88
96
|
[PR 1271](https://github.com/shakacode/react_on_rails/pull/1271) by [ashgaliyev](https://github.com/ashgaliyev).
|
89
97
|
|
90
98
|
- 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).
|
@@ -946,7 +954,8 @@ Best done with Object destructing:
|
|
946
954
|
##### Fixed
|
947
955
|
- Fix several generator related issues.
|
948
956
|
|
949
|
-
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/12.0
|
957
|
+
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/12.1.0...master
|
958
|
+
[12.1.0]: https://github.com/shakacode/react_on_rails/compare/12.0.4...12.1.0
|
950
959
|
[12.0.4]: https://github.com/shakacode/react_on_rails/compare/12.0.3...12.0.4
|
951
960
|
[12.0.3]: https://github.com/shakacode/react_on_rails/compare/12.0.2...12.0.3
|
952
961
|
[12.0.2]: https://github.com/shakacode/react_on_rails/compare/12.0.1...12.0.2
|
data/CONTRIBUTING.md
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
* See other docs in [docs/contributor-info](./docs/contributor-info)
|
6
6
|
|
7
7
|
## To run tests:
|
8
|
+
* [Yalc](https://github.com/whitecolor/yalc) must be installed globally for most local development.
|
8
9
|
* After updating code via git, to prepare all examples and run all tests:
|
9
10
|
|
10
11
|
```sh
|
@@ -64,7 +65,7 @@ yarn
|
|
64
65
|
# Update the lib directory with babel compiled files
|
65
66
|
yarn run build-watch
|
66
67
|
```
|
67
|
-
|
68
|
+
|
68
69
|
You need to do this once:
|
69
70
|
|
70
71
|
```
|
@@ -192,7 +193,7 @@ Then run `bundle`.
|
|
192
193
|
|
193
194
|
The main installer can be run with ```rails generate react_on_rails:install```
|
194
195
|
|
195
|
-
Then use yalc to add the npm module.
|
196
|
+
Then use yalc to add the npm module.
|
196
197
|
|
197
198
|
Be sure that your ran this first at the top level of React on Rails
|
198
199
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
gem "webpacker"
|
4
|
-
gem "bootsnap",
|
4
|
+
gem "bootsnap", require: false
|
5
5
|
gem "rails"
|
6
6
|
gem "sqlite3"
|
7
7
|
gem "sass-rails"
|
@@ -31,6 +31,7 @@ group :development, :test do
|
|
31
31
|
gem "pry-rescue"
|
32
32
|
gem "rubocop", require: false
|
33
33
|
gem "rubocop-performance", require: false
|
34
|
+
gem "rubocop-rspec", require: false
|
34
35
|
gem "scss_lint", require: false
|
35
36
|
gem "spring"
|
36
37
|
end
|
@@ -46,5 +47,5 @@ group :test do
|
|
46
47
|
gem "rspec-rails"
|
47
48
|
gem "rspec-retry"
|
48
49
|
gem "selenium-webdriver"
|
49
|
-
gem "webdrivers", "
|
50
|
+
gem "webdrivers", "3.9.4"
|
50
51
|
end
|
data/README.md
CHANGED
@@ -3,22 +3,21 @@
|
|
3
3
|
<p align="center">
|
4
4
|
<a href="https://shakacode.com/"><img src="https://user-images.githubusercontent.com/10421828/79436256-517d0500-7fd9-11ea-9300-dfbc7c293f26.png"></a>
|
5
5
|
<a href="https://forum.shakacode.com/"><img src="https://user-images.githubusercontent.com/10421828/79436266-53df5f00-7fd9-11ea-94b3-b985e1b05bdc.png"></a>
|
6
|
-
<a href="https://
|
6
|
+
<a href="https://www.shakacode.com/react-on-rails-pro"><img src="https://user-images.githubusercontent.com/10421828/79436265-53df5f00-7fd9-11ea-8220-fc474f6a856c.png"></a>
|
7
7
|
<a href="https://github.com/sponsors/shakacode"><img src="https://user-images.githubusercontent.com/10421828/79466109-cdd90d80-8004-11ea-88e5-25f9a9ddcf44.png"></a>
|
8
8
|
</p>
|
9
9
|
|
10
10
|
---
|
11
11
|
|
12
|
-
[![License](https://img.shields.io/badge/license-mit-green.svg)](
|
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
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
|
-
|
18
17
|
**October 14, 2020**: [RUBY ROGUES
|
19
18
|
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/).
|
20
19
|
|
21
|
-
**October 1, 2020**: See the [spec/dummy](
|
20
|
+
**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
|
22
21
|
that supports SSR.
|
23
22
|
|
24
23
|
**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`.
|
@@ -31,10 +30,10 @@ that supports SSR.
|
|
31
30
|
2. **Typescript bindings**
|
32
31
|
3. **rails/webpacker** "just works" with React on Rails by default.
|
33
32
|
4. i18n support for generating a JSON file rather than a JS file.
|
34
|
-
|
35
|
-
Be sure to see the [CHANGELOG.md](
|
36
|
-
[docs/basics/upgrading-react-on-rails](
|
37
|
-
|
33
|
+
|
34
|
+
Be sure to see the [CHANGELOG.md](https://github.com/shakacode/react_on_rails/tree/master/CHANGELOG.md) and read the upgrade instructions:
|
35
|
+
[docs/basics/upgrading-react-on-rails](https://www.shakacode.com/react-on-rails/docs/basics/upgrading-react-on-rails#upgrading-to-v12).
|
36
|
+
|
38
37
|
* See Justin's RailsConf talk: [Webpacker, It-Just-Works, But How?](http://railsconf.com/2020/video/justin-gordon-webpacker-it-just-works-but-how).
|
39
38
|
* 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).
|
40
39
|
* 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.
|
@@ -46,7 +45,7 @@ React on Rails integrates Rails with (server rendering of) Facebook's [React](ht
|
|
46
45
|
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.
|
47
46
|
|
48
47
|
Interested in optimizing your webpack setup for React on Rails including code
|
49
|
-
splitting with [react-router](https://github.com/ReactTraining/react-router#readme),
|
48
|
+
splitting with [react-router](https://github.com/ReactTraining/react-router#readme),
|
50
49
|
and [loadable-components](https://loadable-components.com/) with server-side rendering?
|
51
50
|
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/).
|
52
51
|
|
@@ -62,28 +61,31 @@ To provide a high performance framework for integrating Ruby on Rails with React
|
|
62
61
|
|
63
62
|
## Features and Why React on Rails?
|
64
63
|
|
65
|
-
Given that `rails/webpacker` gem already provides basic React integration, why would you use "React on Rails"?
|
64
|
+
Given that `rails/webpacker` gem already provides basic React integration, why would you use "React on Rails"?
|
66
65
|
|
67
66
|
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.
|
68
67
|
1. Tight integration with [rails/webpacker](https://github.com/rails/webpacker).
|
69
68
|
1. Server-Side Rendering (SSR), often used for SEO crawler indexing and UX performance, is not offered by `rails/webpacker`.
|
70
69
|
1. [Redux](https://github.com/reactjs/redux) and [React Router](https://github.com/ReactTraining/react-router#readme) integration with server-side-rendering.
|
71
|
-
1. [Internationalization (I18n) and (localization)](https://
|
70
|
+
1. [Internationalization (I18n) and (localization)](https://www.shakacode.com/react-on-rails/docs/basics/i18n)
|
72
71
|
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/).
|
73
72
|
1. [Reason ML Support](https://github.com/shakacode/reason-react-on-rails-example).
|
74
73
|
|
74
|
+
See [Rails/Webpacker React Integration Options](./docs/rails-webpacker-react-integration-options.md) for comparisons to other gems.
|
75
|
+
|
75
76
|
See the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) for an example of a live implementation and code.
|
76
77
|
|
77
78
|
## ShakaCode Forum Premium Content
|
78
79
|
_Requires creating a free account._
|
79
|
-
|
80
|
+
|
80
81
|
* [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)
|
82
|
+
* [How to conditionally render server side based on the device type](https://forum.shakacode.com/t/how-to-conditionally-render-server-side-based-on-the-device-type/1473)
|
81
83
|
|
82
84
|
----
|
83
85
|
|
84
86
|
# Docs
|
85
87
|
|
86
|
-
**Consider browsing this on our [
|
88
|
+
**Consider browsing this on our [website](https://www.shakacode.com/react-on-rails/docs/).**
|
87
89
|
|
88
90
|
## Prerequisites
|
89
91
|
|
@@ -91,40 +93,40 @@ Ruby on Rails >=5 and rails/webpacker 4.2+.
|
|
91
93
|
|
92
94
|
## Getting Started
|
93
95
|
|
94
|
-
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.
|
96
|
+
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.
|
95
97
|
|
96
|
-
1. Do the quick [tutorial](docs/tutorial
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
1. 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).
|
98
|
+
1. Do the quick [tutorial](https://www.shakacode.com/react-on-rails/docs/basics/tutorial).
|
99
|
+
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).
|
100
|
+
3. Look at [spec/dummy](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy), a simple, no DB example.
|
101
|
+
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).
|
101
102
|
|
102
103
|
## Basic Installation
|
103
104
|
|
104
|
-
*See also [the instructions for installing into an existing Rails app](docs/basics/installation-into-an-existing-rails-app
|
105
|
+
*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).*
|
105
106
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
107
|
+
2. Add the `react_on_rails` gem to Gemfile:
|
108
|
+
|
109
|
+
```bash
|
110
|
+
bundle add react_on_rails --strict
|
111
|
+
```
|
112
|
+
|
113
|
+
4. Commit this to git (or else you cannot run the generator unless you pass the option `--ignore-warnings`).
|
112
114
|
|
113
|
-
|
115
|
+
5. Run the generator:
|
114
116
|
|
115
|
-
1. Run the generator:
|
116
117
|
```bash
|
117
118
|
rails generate react_on_rails:install
|
118
119
|
```
|
119
120
|
|
120
|
-
|
121
|
+
6. Start the app:
|
122
|
+
|
121
123
|
```bash
|
122
124
|
rails s
|
123
125
|
```
|
124
126
|
|
125
|
-
|
127
|
+
7. Visit http://localhost:3000/hello_world.
|
128
|
+
|
126
129
|
|
127
|
-
|
128
130
|
### Turning on server rendering
|
129
131
|
|
130
132
|
With the code from running the React on Rails generator above:
|
@@ -147,8 +149,8 @@ issue.
|
|
147
149
|
|
148
150
|
### Configuration
|
149
151
|
|
150
|
-
* Configure `config/initializers/react_on_rails.rb`. You can adjust some necessary settings and defaults. See file [docs/basics/configuration.md](docs/basics/configuration
|
151
|
-
* 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](
|
152
|
+
* 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.
|
153
|
+
* 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).
|
152
154
|
* 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.
|
153
155
|
* Your `public_output_path` must match your custom Webpack configuration for `output` of your bundles.
|
154
156
|
* Only set `cache_manifest` to `true` in your production env.
|
@@ -183,9 +185,9 @@ issue.
|
|
183
185
|
# Rails View
|
184
186
|
<%= react_component("HelloWorld", props: { name: "Stranger" }) %>
|
185
187
|
```
|
186
|
-
|
187
|
-
- 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
|
188
|
-
|
188
|
+
|
189
|
+
- 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.
|
190
|
+
|
189
191
|
```js
|
190
192
|
import React from 'react';
|
191
193
|
|
@@ -198,9 +200,9 @@ issue.
|
|
198
200
|
</div>
|
199
201
|
);
|
200
202
|
};
|
201
|
-
```
|
202
|
-
|
203
|
-
See the [View Helpers API](
|
203
|
+
```
|
204
|
+
|
205
|
+
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`.
|
204
206
|
|
205
207
|
## Globally Exposing Your React Components
|
206
208
|
|
@@ -219,7 +221,7 @@ This is how to expose a component to the `react_component` view helper.
|
|
219
221
|
|
220
222
|
#### Different Server-Side Rendering Code (and a Server-Specific Bundle)
|
221
223
|
|
222
|
-
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() }`.
|
224
|
+
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() }`.
|
223
225
|
|
224
226
|
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.
|
225
227
|
|
@@ -229,7 +231,7 @@ For details on techniques to use different code for client and server rendering,
|
|
229
231
|
|
230
232
|
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:
|
231
233
|
|
232
|
-
1. You to have access to the `railsContext`. See [documentation for the railsContext](
|
234
|
+
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`.
|
233
235
|
2. You can use the passed-in props to initialize a redux store or set up react-router.
|
234
236
|
3. You can return different components depending on what's in the props.
|
235
237
|
|
@@ -255,7 +257,7 @@ Thus, there is no difference between registering a React Function Component or c
|
|
255
257
|
|
256
258
|
## react_component_hash for Render-Functions
|
257
259
|
|
258
|
-
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`.
|
260
|
+
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`.
|
259
261
|
|
260
262
|
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:
|
261
263
|
|
@@ -263,7 +265,7 @@ For server rendering, if you wish to return multiple HTML strings from a Render-
|
|
263
265
|
{ renderedHtml: { componentHtml, customKey1, customKey2} }
|
264
266
|
```
|
265
267
|
|
266
|
-
For details on using react_component_hash with react-helmet, see
|
268
|
+
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).
|
267
269
|
|
268
270
|
## Error Handling
|
269
271
|
|
@@ -273,19 +275,19 @@ For details on using react_component_hash with react-helmet, see the docs below
|
|
273
275
|
## I18n
|
274
276
|
|
275
277
|
React on Rails provides an option for automatic conversions of Rails `*.yml` locale files into `*.json` or `*.js*.
|
276
|
-
See the [How to add I18n](docs/basics/i18n
|
278
|
+
See the [How to add I18n](https://www.shakacode.com/react-on-rails/docs/basics/i18n) for a summary of adding I18n.
|
277
279
|
|
278
280
|
## More Details
|
279
281
|
|
280
|
-
Browse the links in the [Summary Table of Contents](
|
282
|
+
Browse the links in the [Summary Table of Contents](https://github.com/shakacode/react_on_rails/tree/master/SUMMARY.md)
|
281
283
|
|
282
284
|
Here are some highly recommended next articles to read:
|
283
285
|
|
284
|
-
1. [How React on Rails Works](docs/
|
285
|
-
1. [Webpack Configuration](
|
286
|
-
1. [View Helpers API](
|
286
|
+
1. [How React on Rails Works](https://www.shakacode.com/react-on-rails/docs/basics/how-react-on-rails-works)
|
287
|
+
1. [Webpack Configuration](https://www.shakacode.com/react-on-rails/docs/basics/webpack-configuration)
|
288
|
+
1. [View Helpers API](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api)
|
287
289
|
1. [Caching and Performance: React on Rails Pro](https://www.shakacode.com/react-on-rails-pro).
|
288
|
-
1. [Deployment](docs/basics/deployment
|
290
|
+
1. [Deployment](https://www.shakacode.com/react-on-rails/docs/basics/deployment).
|
289
291
|
|
290
292
|
# Support
|
291
293
|
|
@@ -301,20 +303,20 @@ Please [**click to subscribe**](https://app.mailerlite.com/webforms/landing/l1d9
|
|
301
303
|
- **[forum.shakacode.com](https://forum.shakacode.com)**: Post your questions
|
302
304
|
- **[@railsonmaui on Twitter](https://twitter.com/railsonmaui)**
|
303
305
|
- 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).
|
304
|
-
- See [Projects](PROJECTS.md) using and [KUDOS](
|
305
|
-
- *See [NEWS.md](NEWS.md) for more notes over time.*
|
306
|
+
- 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.
|
307
|
+
- *See [NEWS.md](https://github.com/shakacode/react_on_rails/tree/master/NEWS.md) for more notes over time.*
|
306
308
|
|
307
309
|
## Contributing
|
308
310
|
|
309
|
-
Bug reports and pull requests are welcome. See [Contributing](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).
|
311
|
+
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).
|
310
312
|
|
311
313
|
## React on Rails Pro
|
312
314
|
|
313
|
-
React on Rails Pro
|
315
|
+
Support React on Rails Pro development [by becoming a Github sponsor](https://github.com/sponsors/shakacode) and get these benefits.
|
314
316
|
|
315
|
-
|
317
|
+
React on Rails Pro includes 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://www.shakacode.com/blog/hvmns-90-reduction-in-server-response-time-from-react-on-rails-pro/). The [Wiki](https://github.com/shakacode/react_on_rails/wiki) contains more details.
|
316
318
|
|
317
|
-
|
319
|
+
[![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)
|
318
320
|
|
319
321
|
The [React on Rails Pro Support Plan](https://www.shakacode.com/react-on-rails-pro) can help!
|
320
322
|
|
@@ -328,7 +330,7 @@ ShakaCode can also help you with your custom software development needs. We spec
|
|
328
330
|
|
329
331
|
Please email Justin Gordon [justin@shakacode.com](mailto:justin@shakacode.com), the maintainer of React on Rails, for more information.
|
330
332
|
|
331
|
-
### Fragment Caching
|
333
|
+
### Pro: Fragment Caching
|
332
334
|
|
333
335
|
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:
|
334
336
|
|
@@ -349,16 +351,16 @@ Such fragment caching saves CPU work for your web server and greatly reduces the
|
|
349
351
|
4. Creating the HTML string containing the props and the server-rendered JavaScript code.
|
350
352
|
|
351
353
|
Note, even without server rendering (without step 3 above), fragment caching is still effective.
|
352
|
-
|
353
|
-
|
354
|
+
|
355
|
+
### Pro: Integration with Node.js for Server Rendering
|
354
356
|
|
355
357
|
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).
|
356
358
|
|
357
359
|
## Testimonials for ShakaCode
|
358
|
-
[HVMN Testimonial, by Paul Benigeri, October 12, 2018](
|
360
|
+
[HVMN Testimonial, by Paul Benigeri, October 12, 2018](https://www.shakacode.com/react-on-rails/docs/testimonials/hvmn)
|
359
361
|
> 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.
|
360
362
|
|
361
|
-
[ResortPass Testimonial, by Leora Juster, December 10, 2018](
|
363
|
+
[ResortPass Testimonial, by Leora Juster, December 10, 2018](https://www.shakacode.com/react-on-rails/docs/testimonials/resortpass)
|
362
364
|
|
363
365
|
> 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.
|
364
366
|
|
@@ -366,16 +368,17 @@ From Joel Hooks, Co-Founder, Chief Nerd at [egghead.io](https://egghead.io/), Ja
|
|
366
368
|
|
367
369
|
![2017-01-30_11-33-59](https://cloud.githubusercontent.com/assets/1118459/22443635/b3549fb4-e6e3-11e6-8ea2-6f589dc93ed3.png)
|
368
370
|
|
369
|
-
For more testimonials, see [Live Projects](PROJECTS.md) and [Kudos](
|
371
|
+
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).
|
370
372
|
|
371
373
|
# Supporters
|
372
374
|
|
373
|
-
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 [
|
375
|
+
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 [HiChee.com](https://HiChee.com), [Rails AutoScale](https://railsautoscale.com) to scale the dynos of HiChee, [BrowserStack](https://www.browserstack.com) to solve problems with oddball browsers.
|
374
376
|
|
375
377
|
[![2019-09-24_17-48-00](https://user-images.githubusercontent.com/1118459/65567887-96353780-def3-11e9-926d-4a55e2e186ff.png)](https://www.jetbrains.com/ruby/)
|
376
378
|
[![Scout](https://user-images.githubusercontent.com/1118459/41828269-106b40f8-77d0-11e8-8d19-9c4b167ef9d8.png)](https://scoutapp.com/)
|
379
|
+
[![2020-12-27_21-26-19](https://user-images.githubusercontent.com/1118459/103197530-48dc0e80-488a-11eb-8b1b-a16664b30274.png)](https://railsautoscale.com/)
|
377
380
|
[![BrowserStack](https://cloud.githubusercontent.com/assets/1118459/23203304/1261e468-f886-11e6-819e-93b1a3f17da4.png)](https://www.browserstack.com)
|
378
|
-
|
381
|
+
|
379
382
|
|
380
383
|
## Clubhouse
|
381
384
|
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!
|
@@ -385,8 +388,8 @@ I've just moved ShakaCode's development to [ClubHouse](https://clubhouse.io/) fr
|
|
385
388
|
Aloha and best wishes from Justin and the ShakaCode team!
|
386
389
|
|
387
390
|
# Work with Us
|
388
|
-
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 [
|
391
|
+
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 [HiChee](https://hichee.com). Your main coding interview will be pairing with us on our open source! We're also using [ReasonML](https://reasonml.github.io/) extensively!
|
389
392
|
|
390
393
|
# License
|
391
394
|
|
392
|
-
The gem is available as open source under the terms of the [MIT License](LICENSE.md).
|
395
|
+
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).
|