react_on_rails 11.1.7 → 12.0.0.pre.beta.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 +320 -0
- data/.eslintignore +2 -1
- data/.eslintrc +30 -2
- data/.github/FUNDING.yml +1 -0
- data/.gitignore +3 -1
- data/.prettierignore +10 -0
- data/.prettierrc +23 -0
- data/.release-it.json +3 -0
- data/.rubocop.yml +37 -11
- data/.travis.yml +10 -20
- data/CHANGELOG.md +86 -3
- data/CONTRIBUTING.md +61 -80
- data/Gemfile +3 -5
- data/{COMM-LICENSE → REACT-ON-RAILS-PRO-LICENSE} +6 -9
- data/README.md +117 -68
- data/Rakefile +0 -7
- data/SUMMARY.md +12 -12
- data/book.json +5 -5
- data/docs/additional-reading/asset-pipeline.md +8 -16
- data/docs/additional-reading/images.md +1 -1
- data/docs/additional-reading/rails_view_rendering_from_inline_javascript.md +2 -1
- data/docs/additional-reading/react-helmet.md +30 -10
- data/docs/additional-reading/react-router.md +52 -75
- data/docs/additional-reading/server-rendering-tips.md +12 -7
- data/docs/additional-reading/upgrade-webpacker-v3-to-v4.md +10 -0
- data/docs/api/javascript-api.md +3 -3
- data/docs/api/redux-store-api.md +4 -2
- data/docs/api/view-helpers-api.md +17 -14
- data/docs/basics/configuration.md +64 -61
- data/docs/basics/deployment.md +1 -2
- data/docs/basics/generator-details.md +1 -1
- data/docs/basics/i18n.md +44 -22
- data/docs/basics/installation-into-an-existing-rails-app.md +2 -2
- data/docs/basics/minitest-configuration.md +31 -0
- data/docs/basics/react-server-rendering.md +3 -1
- data/docs/basics/recommended-project-structure.md +24 -1
- data/docs/basics/{generator-functions-and-railscontext.md → render-functions-and-railscontext.md} +59 -21
- data/docs/basics/rspec-configuration.md +2 -2
- data/docs/basics/upgrading-react-on-rails.md +61 -3
- data/docs/basics/webpack-configuration.md +26 -1
- data/docs/contributor-info/errors-with-hooks.md +45 -0
- data/docs/contributor-info/pull-requests.md +44 -0
- data/docs/misc/doctrine.md +1 -1
- data/docs/{misc-pending → outdated}/code-splitting.md +13 -9
- data/docs/{additional-reading → outdated}/heroku-deployment.md +0 -6
- data/docs/{basics → outdated}/how-react-on-rails-works.md +2 -2
- data/docs/{misc-pending → outdated}/manual-installation-overview.md +5 -5
- data/docs/{additional-reading → outdated}/rails-assets-relative-paths.md +3 -3
- data/docs/{misc-pending → outdated}/rails-assets.md +4 -7
- data/docs/{misc → outdated}/rails3.md +0 -0
- data/docs/testimonials/hvmn.md +25 -0
- data/docs/testimonials/resortpass.md +13 -0
- data/docs/testimonials/testimonials.md +28 -0
- data/docs/tutorial.md +157 -25
- data/jest.config.js +4 -0
- data/lib/generators/react_on_rails/dev_tests_generator.rb +2 -1
- data/lib/generators/react_on_rails/generator_helper.rb +4 -6
- data/lib/generators/react_on_rails/install_generator.rb +2 -0
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +9 -8
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +4 -8
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/store/helloWorldStore.js +1 -3
- data/lib/react_on_rails.rb +4 -1
- data/lib/react_on_rails/configuration.rb +15 -23
- data/lib/react_on_rails/error.rb +2 -0
- data/lib/react_on_rails/git_utils.rb +2 -0
- data/lib/react_on_rails/helper.rb +110 -159
- data/lib/react_on_rails/json_output.rb +1 -1
- data/lib/react_on_rails/json_parse_error.rb +2 -0
- data/lib/react_on_rails/locales/base.rb +142 -0
- data/lib/react_on_rails/locales/to_js.rb +37 -0
- data/lib/react_on_rails/locales/to_json.rb +27 -0
- data/lib/react_on_rails/prerender_error.rb +11 -15
- data/lib/react_on_rails/react_component/render_options.rb +4 -0
- data/lib/react_on_rails/server_rendering_js_code.rb +42 -0
- data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +85 -60
- data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +7 -8
- data/lib/react_on_rails/utils.rb +19 -20
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/react_on_rails/version_checker.rb +5 -1
- data/lib/react_on_rails/webpacker_utils.rb +21 -2
- data/lib/tasks/assets.rake +5 -45
- data/lib/tasks/locale.rake +8 -2
- data/package-scripts.yml +49 -0
- data/package.json +41 -31
- data/rakelib/dummy_apps.rake +1 -9
- data/rakelib/example_type.rb +3 -1
- data/rakelib/examples.rake +3 -0
- data/rakelib/lint.rake +2 -7
- data/rakelib/node_package.rake +2 -2
- data/rakelib/release.rake +3 -2
- data/rakelib/run_rspec.rake +5 -18
- data/react_on_rails.gemspec +3 -5
- data/tsconfig.json +14 -0
- data/webpackConfigLoader.js +5 -4
- data/yarn.lock +7042 -2327
- metadata +40 -57
- data/Gemfile.rails32 +0 -74
- data/docs/additional-reading/babel.md +0 -5
- data/docs/additional-reading/hot-reloading-rails-development.md +0 -57
- data/docs/api/ruby-api-hot-reload-view-helpers.md +0 -44
- data/docs/testimonials.md +0 -11
- data/lib/react_on_rails/assets_precompile.rb +0 -150
- data/lib/react_on_rails/locales_to_js.rb +0 -136
@@ -0,0 +1,28 @@
|
|
1
|
+
# Testimonials
|
2
|
+
# [HVMN Testimonial, Written by Paul Benigeri, October 12, 2018](./hvmn.md)
|
3
|
+
|
4
|
+
> 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.
|
5
|
+
|
6
|
+
Full writeup [here](./hvmn.md).
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
# [Leora from ResortPass](./resortpass.md), December 10, 2018
|
11
|
+
|
12
|
+
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.
|
13
|
+
|
14
|
+
Full writeup [here](./testimonials/resortpass.md).
|
15
|
+
|
16
|
+
---
|
17
|
+
|
18
|
+
From Joel Hooks, Co-Founder, Chief Nerd at [egghead.io](https://egghead.io/), January 30, 2017:
|
19
|
+
|
20
|
+
![2017-01-30_11-33-59](https://cloud.githubusercontent.com/assets/1118459/22443635/b3549fb4-e6e3-11e6-8ea2-6f589dc93ed3.png)
|
21
|
+
|
22
|
+
---
|
23
|
+
|
24
|
+
From Kyle Maune of Cooper Aerial, May 4, 2018
|
25
|
+
|
26
|
+
![image](https://user-images.githubusercontent.com/1118459/40891236-9b0b406e-671d-11e8-80ee-c026dbd1d5a2.png)
|
27
|
+
|
28
|
+
For more testimonials, see [Live Projects](PROJECTS.md) and [Kudos](KUDOS.md).
|
data/docs/tutorial.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# React on Rails Basic Tutorial
|
2
2
|
|
3
|
-
|
3
|
+
*Updated for Ruby 2.7.1, Rails 6.0.3.1, and React on Rails v12.0.0*
|
4
|
+
|
5
|
+
This tutorial guides you through setting up a new or existing Rails app with **React on Rails**, demonstrating Rails + React + Redux + Server Rendering.
|
4
6
|
|
5
7
|
After finishing this tutorial you will get an application that can do the following (live on Heroku):
|
6
8
|
|
@@ -17,9 +19,9 @@ By the time you read this, the latest may have changed. Be sure to check the ver
|
|
17
19
|
|
18
20
|
_Note: some of the screen images below show the "npm" command. react_on_rails 6.6.0 and greater uses `yarn`._
|
19
21
|
|
20
|
-
## Setting up
|
22
|
+
## Setting up your environment
|
21
23
|
|
22
|
-
Trying out **React on Rails** is super easy, so long as you have the basic prerequisites. This includes the basics for Rails
|
24
|
+
Trying out **React on Rails** is super easy, so long as you have the basic prerequisites. This includes the basics for Rails 6.x and node version 13+. I recommend `rvm` and `nvm` to install Ruby and Node, and [brew](https://brew.sh/) to install [yarn](https://yarnpkg.com/en/docs/install#mac-tab). Rails can be installed as an ordinary gem.
|
23
25
|
|
24
26
|
```
|
25
27
|
nvm install node # download and install latest stable Node
|
@@ -27,9 +29,8 @@ nvm alias default node # make it default version
|
|
27
29
|
nvm list # check
|
28
30
|
|
29
31
|
brew install yarn # you can use other installer if desired
|
30
|
-
|
31
|
-
rvm
|
32
|
-
rvm use 2.5.0 --default # use it and make it default
|
32
|
+
rvm install 2.7 # download and install latest stable Ruby (update to exact version)
|
33
|
+
rvm use 2.7 --default # use it and make it default
|
33
34
|
rvm list # check
|
34
35
|
|
35
36
|
gem install rails # download and install latest stable Rails
|
@@ -44,53 +45,90 @@ First be sure to run `rails -v` and check you are using Rails 5.1.3 or above. If
|
|
44
45
|
cd <directory where you want to create your new Rails app>
|
45
46
|
|
46
47
|
# any name you like for the rails app
|
47
|
-
rails new test-react-on-rails --webpack=react
|
48
|
+
rails new test-react-on-rails --webpack=react --skip-sprockets
|
48
49
|
|
49
50
|
cd test-react-on-rails
|
51
|
+
bundle
|
50
52
|
```
|
51
53
|
|
52
|
-
Note: if you are
|
54
|
+
Note: if you are adding React On Rails to an existing app you will instead to run these two commands as well:
|
53
55
|
|
54
56
|
```
|
55
57
|
bundle exec rails webpacker:install
|
56
58
|
bundle exec rails webpacker:install:react
|
57
59
|
```
|
58
60
|
|
59
|
-
|
61
|
+
Let's commit everything before installing React on Rails.
|
62
|
+
|
63
|
+
```
|
64
|
+
# Here are git commands to make a new git repo and commit everything.
|
65
|
+
# Newer versions of Rails create the git repo by default.
|
66
|
+
git add -A
|
67
|
+
git commit -m "Initial commit"
|
68
|
+
```
|
69
|
+
|
70
|
+
Add the **React On Rails** gem to your `Gemfile`:
|
60
71
|
|
61
72
|
```
|
62
|
-
gem 'react_on_rails', '
|
73
|
+
gem 'react_on_rails', '12.0.0' # prefer exact gem version to match npm version
|
63
74
|
```
|
64
75
|
|
65
76
|
Note: Latest released React On Rails version is considered stable. Please use the latest version to ensure you get all the security patches and the best support.
|
66
77
|
|
67
|
-
Run `bundle` and commit the
|
68
|
-
|
78
|
+
Run `bundle` and commit the changes.
|
69
79
|
|
70
80
|
```
|
71
81
|
bundle
|
72
82
|
|
73
|
-
|
74
|
-
# Newer versions of Rails create the git repo by default.
|
75
|
-
git add -A
|
76
|
-
git commit -m "Initial commit"
|
83
|
+
git commit -am "Added React on Rails Gem"
|
77
84
|
```
|
78
85
|
|
79
86
|
Install React on Rails: `rails generate react_on_rails:install` or `rails generate react_on_rails:install --redux`. You need to first git commit your files before running the generator, or else it will generate an error.
|
80
87
|
|
81
88
|
```
|
82
89
|
rails generate react_on_rails:install
|
83
|
-
bundle && yarn
|
84
90
|
```
|
85
91
|
|
86
|
-
|
92
|
+
Then run server with static client side files:
|
87
93
|
|
88
94
|
```
|
89
95
|
foreman start -f Procfile.dev
|
90
96
|
```
|
91
97
|
|
92
|
-
|
93
|
-
|
98
|
+
To run with the webpack-dev-server:
|
99
|
+
```
|
100
|
+
foreman start -f Procfile.dev-server
|
101
|
+
```
|
102
|
+
|
103
|
+
Visit [http://localhost:3000/hello_world](http://localhost:3000/hello_world) and see your **React On Rails** app running!
|
104
|
+
|
105
|
+
*Note, foreman may default to PORT 5000 unless you set the value of PORT in your environment or in the Procfile.*
|
106
|
+
|
107
|
+
# HMR vs. React Hot Reloading
|
108
|
+
|
109
|
+
First, check that the `hmr` option is `true` in your `config/webpacker.yml` file.
|
110
|
+
|
111
|
+
The basic setup will have HMR working with the default webpacker setup. However, the basic will cause a full page refresh each time you save a file.
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
|
94
132
|
|
95
133
|
### Custom IP & PORT setup (Cloud9 example)
|
96
134
|
|
@@ -115,7 +153,7 @@ It's super important to exclude certain directories from RubyMine or else it wil
|
|
115
153
|
### Create Your Heroku App
|
116
154
|
*Assuming you can login to heroku.com and have logged into to your shell for heroku.*
|
117
155
|
|
118
|
-
1. Visit https://dashboard.heroku.com/new and create an app, say named `my-name-react-on-rails`:
|
156
|
+
1. Visit [https://dashboard.heroku.com/new](https://dashboard.heroku.com/new) and create an app, say named `my-name-react-on-rails`:
|
119
157
|
|
120
158
|
![06](https://cloud.githubusercontent.com/assets/20628911/17465014/1f29bf3c-5cf4-11e6-869f-4215987ae854.png)
|
121
159
|
|
@@ -137,10 +175,11 @@ Set heroku to use multiple buildpacks:
|
|
137
175
|
gem 'pg'
|
138
176
|
```
|
139
177
|
|
140
|
-
|
178
|
+
2. Run `bundle`
|
141
179
|
|
180
|
+
![07](https://cloud.githubusercontent.com/assets/20628911/17465015/1f2f4042-5cf4-11e6-8287-2fb077550809.png)
|
142
181
|
|
143
|
-
|
182
|
+
3. Replace your `database.yml` file with this (assuming your app name is "ror").
|
144
183
|
|
145
184
|
```yml
|
146
185
|
default: &default
|
@@ -185,11 +224,15 @@ root "hello_world#index"
|
|
185
224
|
|
186
225
|
Next, configure your app for Puma, per the [instructions on Heroku](https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server).
|
187
226
|
|
227
|
+
Create `/Procfile`. This is what Heroku uses to start your app.
|
228
|
+
|
188
229
|
`Procfile`
|
189
230
|
```
|
190
231
|
web: bundle exec puma -C config/puma.rb
|
191
232
|
```
|
192
233
|
|
234
|
+
Note, newer versions of Rails create this file automatically. However, the [docs on Heroku](https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#config) have something a bit different, so please make it conform to those docs. As of 2018-10-13, the docs looked like this:
|
235
|
+
|
193
236
|
`config/puma.rb`
|
194
237
|
```rb
|
195
238
|
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
|
@@ -213,8 +256,97 @@ Then after all changes are done don't forget to commit them with git and finally
|
|
213
256
|
|
214
257
|
```
|
215
258
|
git add -A
|
216
|
-
git commit -m "
|
259
|
+
git commit -m "Changes for Heroku"
|
217
260
|
git push heroku master
|
218
261
|
```
|
219
262
|
|
220
|
-
|
263
|
+
Then run:
|
264
|
+
|
265
|
+
```
|
266
|
+
heroku open
|
267
|
+
```
|
268
|
+
|
269
|
+
and you will see your live app and you can share this URL with your friends. Congrats!
|
270
|
+
|
271
|
+
|
272
|
+
## Turning on Server Rendering
|
273
|
+
|
274
|
+
You can turn on server rendering by simply changing the `prerender` option to `true`:
|
275
|
+
|
276
|
+
```erb
|
277
|
+
<%= react_component("HelloWorld", props: @hello_world_props, prerender: true) %>
|
278
|
+
```
|
279
|
+
|
280
|
+
If you want to test this out with HMR, then you also need to add this line to your
|
281
|
+
`config/intializers/react_on_rails.rb`
|
282
|
+
|
283
|
+
```ruby
|
284
|
+
config.same_bundle_for_client_and_server = true
|
285
|
+
```
|
286
|
+
|
287
|
+
More likely, you will create a different build file for server rendering. However, if you want to
|
288
|
+
use the same file from the webpack-dev-server, you'll need to add that line.
|
289
|
+
|
290
|
+
Then push to Heroku:
|
291
|
+
|
292
|
+
```
|
293
|
+
git add -A
|
294
|
+
git commit -m "Enable server rendering"
|
295
|
+
git push heroku master
|
296
|
+
```
|
297
|
+
|
298
|
+
When you look at the source code for the page (right click, view source in Chrome), you can see the difference between non-server rendering, where your DIV containing your React looks like this:
|
299
|
+
|
300
|
+
```html
|
301
|
+
<div id="HelloWorld-react-component-b7ae1dc6-396c-411d-886a-269633b3f604"></div>
|
302
|
+
```
|
303
|
+
|
304
|
+
versus with server rendering:
|
305
|
+
|
306
|
+
```html
|
307
|
+
<div id="HelloWorld-react-component-d846ce53-3b82-4c4a-8f32-ffc347c8444a"><div data-reactroot=""><h3>Hello, <!-- -->Stranger<!-- -->!</h3><hr/><form><label for="name">Say hello to:</label><input type="text" id="name" value="Stranger"/></form></div></div>
|
308
|
+
```
|
309
|
+
|
310
|
+
For more details on server rendering, see:
|
311
|
+
|
312
|
+
+ [Client vs. Server Rendering](./basics/client-vs-server-rendering.md)
|
313
|
+
+ [React Server Rendering](./basics/react-server-rendering.md)
|
314
|
+
|
315
|
+
## Moving from the Rails default `/app/javascript` to the recommended `/client` structure
|
316
|
+
|
317
|
+
ShakaCode recommends that you use `/client` for your client side app. This way a non-Rails, front-end developer can be at home just by opening up the `/client` directory.
|
318
|
+
|
319
|
+
|
320
|
+
1. Move the directory:
|
321
|
+
|
322
|
+
```
|
323
|
+
mv app/javascript client
|
324
|
+
```
|
325
|
+
|
326
|
+
2. Edit your `/config/webpacker.yml` file. Change the `default/source_path`:
|
327
|
+
|
328
|
+
```yml
|
329
|
+
source_path: client
|
330
|
+
```
|
331
|
+
|
332
|
+
## Using HMR with the rails/webpacker setup
|
333
|
+
|
334
|
+
Start the app using `foreman start -f Procfile.dev-server`.
|
335
|
+
|
336
|
+
When you change a JSX file and save, the browser will automatically refresh!
|
337
|
+
|
338
|
+
So you get some basics from HMR with no code changes. If you want to go further, take a look at these links:
|
339
|
+
|
340
|
+
* https://github.com/rails/webpacker/blob/master/docs/webpack-dev-server.md
|
341
|
+
* https://webpack.js.org/configuration/dev-server/
|
342
|
+
* https://webpack.js.org/concepts/hot-module-replacement/
|
343
|
+
|
344
|
+
React on Rails will automatically handle disabling server rendering if there is only one bundle file created by the Webpack development server by rails/webpacker.
|
345
|
+
|
346
|
+
## Conclusion
|
347
|
+
|
348
|
+
* Browse the docs either on the [gitbook](https://shakacode.gitbooks.io/react-on-rails/content/) or in the [docs directory on github](https://github.com/shakacode/react_on_rails/tree/master/docs)
|
349
|
+
|
350
|
+
Feedback is greatly appreciated! As are stars on github!
|
351
|
+
|
352
|
+
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.
|
data/jest.config.js
ADDED
@@ -36,6 +36,7 @@ module ReactOnRails
|
|
36
36
|
|
37
37
|
def replace_prerender_if_server_rendering
|
38
38
|
return unless options.example_server_rendering
|
39
|
+
|
39
40
|
hello_world_index = File.join(destination_root, "app", "views", "hello_world", "index.html.erb")
|
40
41
|
hello_world_contents = File.read(hello_world_index)
|
41
42
|
new_hello_world_contents = hello_world_contents.gsub(/prerender: false/,
|
@@ -49,7 +50,7 @@ module ReactOnRails
|
|
49
50
|
contents = File.read(package_json)
|
50
51
|
replacement_value = <<-STRING
|
51
52
|
"scripts": {
|
52
|
-
"postinstall": "
|
53
|
+
"postinstall": "yalc link react-on-rails",
|
53
54
|
STRING
|
54
55
|
new_client_package_json_contents = contents.gsub(/ {2}"scripts": {/,
|
55
56
|
replacement_value)
|
@@ -15,13 +15,11 @@ module GeneratorHelper
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def setup_file_error(file, data)
|
18
|
-
|
19
|
-
|
20
|
-
#{file}
|
21
|
-
|
22
|
-
#{data}
|
18
|
+
<<~MSG
|
19
|
+
#{file} was not found.
|
20
|
+
Please add the following content to your #{file} file:
|
21
|
+
#{data}
|
23
22
|
MSG
|
24
|
-
# rubocop:enable Layout/IndentHeredoc
|
25
23
|
end
|
26
24
|
|
27
25
|
def empty_directory_with_keep_file(destination, config = {})
|
@@ -62,6 +62,7 @@ module ReactOnRails
|
|
62
62
|
|
63
63
|
def missing_yarn?
|
64
64
|
return false unless ReactOnRails::Utils.running_on_windows? ? `where yarn`.blank? : `which yarn`.blank?
|
65
|
+
|
65
66
|
error = "yarn is required. Please install it before continuing. https://yarnpkg.com/en/docs/install"
|
66
67
|
GeneratorMessages.add_error(error)
|
67
68
|
true
|
@@ -69,6 +70,7 @@ module ReactOnRails
|
|
69
70
|
|
70
71
|
def missing_node?
|
71
72
|
return false unless ReactOnRails::Utils.running_on_windows? ? `where node`.blank? : `which node`.blank?
|
73
|
+
|
72
74
|
error = "** nodejs is required. Please install it before continuing. https://nodejs.org/en/"
|
73
75
|
GeneratorMessages.add_error(error)
|
74
76
|
true
|
@@ -25,19 +25,20 @@ export default class HelloWorld extends React.Component {
|
|
25
25
|
return (
|
26
26
|
<div>
|
27
27
|
<h3>
|
28
|
-
Hello,
|
28
|
+
Hello,
|
29
|
+
{this.state.name}!
|
29
30
|
</h3>
|
30
31
|
<hr />
|
31
|
-
<form
|
32
|
+
<form>
|
32
33
|
<label htmlFor="name">
|
33
34
|
Say hello to:
|
35
|
+
<input
|
36
|
+
id="name"
|
37
|
+
type="text"
|
38
|
+
value={this.state.name}
|
39
|
+
onChange={(e) => this.updateName(e.target.value)}
|
40
|
+
/>
|
34
41
|
</label>
|
35
|
-
<input
|
36
|
-
id="name"
|
37
|
-
type="text"
|
38
|
-
value={this.state.name}
|
39
|
-
onChange={(e) => this.updateName(e.target.value)}
|
40
|
-
/>
|
41
42
|
</form>
|
42
43
|
</div>
|
43
44
|
);
|
@@ -4,19 +4,15 @@ import React from 'react';
|
|
4
4
|
const HelloWorld = ({ name, updateName }) => (
|
5
5
|
<div>
|
6
6
|
<h3>
|
7
|
-
Hello,
|
7
|
+
Hello,
|
8
|
+
{name}!
|
8
9
|
</h3>
|
9
10
|
<hr />
|
10
|
-
<form
|
11
|
+
<form>
|
11
12
|
<label htmlFor="name">
|
12
13
|
Say hello to:
|
14
|
+
<input id="name" type="text" value={name} onChange={(e) => updateName(e.target.value)} />
|
13
15
|
</label>
|
14
|
-
<input
|
15
|
-
id="name"
|
16
|
-
type="text"
|
17
|
-
value={name}
|
18
|
-
onChange={(e) => updateName(e.target.value)}
|
19
|
-
/>
|
20
16
|
</form>
|
21
17
|
</div>
|
22
18
|
);
|
@@ -1,8 +1,6 @@
|
|
1
1
|
import { createStore } from 'redux';
|
2
2
|
import helloWorldReducer from '../reducers/helloWorldReducer';
|
3
3
|
|
4
|
-
const configureStore = (railsProps) => (
|
5
|
-
createStore(helloWorldReducer, railsProps)
|
6
|
-
);
|
4
|
+
const configureStore = (railsProps) => createStore(helloWorldReducer, railsProps);
|
7
5
|
|
8
6
|
export default configureStore;
|
data/lib/react_on_rails.rb
CHANGED
@@ -11,6 +11,7 @@ require "react_on_rails/version"
|
|
11
11
|
require "react_on_rails/version_checker"
|
12
12
|
require "react_on_rails/configuration"
|
13
13
|
require "react_on_rails/server_rendering_pool"
|
14
|
+
require "react_on_rails/server_rendering_js_code"
|
14
15
|
require "react_on_rails/engine"
|
15
16
|
require "react_on_rails/react_component/render_options"
|
16
17
|
require "react_on_rails/version_syntax_converter"
|
@@ -21,4 +22,6 @@ require "react_on_rails/webpacker_utils"
|
|
21
22
|
require "react_on_rails/test_helper/webpack_assets_compiler"
|
22
23
|
require "react_on_rails/test_helper/webpack_assets_status_checker"
|
23
24
|
require "react_on_rails/test_helper/ensure_assets_compiled"
|
24
|
-
require "react_on_rails/
|
25
|
+
require "react_on_rails/locales/base"
|
26
|
+
require "react_on_rails/locales/to_js"
|
27
|
+
require "react_on_rails/locales/to_json"
|
@@ -21,7 +21,7 @@ module ReactOnRails
|
|
21
21
|
prerender: false,
|
22
22
|
replay_console: true,
|
23
23
|
logging_on_server: true,
|
24
|
-
raise_on_prerender_error:
|
24
|
+
raise_on_prerender_error: Rails.env.development?,
|
25
25
|
trace: Rails.env.development?,
|
26
26
|
development_mode: Rails.env.development?,
|
27
27
|
server_renderer_pool_size: DEFAULT_POOL_SIZE,
|
@@ -31,10 +31,11 @@ module ReactOnRails
|
|
31
31
|
webpack_generated_files: %w[manifest.json],
|
32
32
|
rendering_extension: nil,
|
33
33
|
server_render_method: nil,
|
34
|
-
symlink_non_digested_assets_regex: nil,
|
35
34
|
build_test_command: "",
|
36
35
|
build_production_command: "",
|
37
|
-
random_dom_id: DEFAULT_RANDOM_DOM_ID
|
36
|
+
random_dom_id: DEFAULT_RANDOM_DOM_ID,
|
37
|
+
same_bundle_for_client_and_server: false,
|
38
|
+
i18n_output_format: nil
|
38
39
|
)
|
39
40
|
end
|
40
41
|
|
@@ -46,8 +47,9 @@ module ReactOnRails
|
|
46
47
|
:generated_assets_dirs, :generated_assets_dir,
|
47
48
|
:webpack_generated_files, :rendering_extension, :build_test_command,
|
48
49
|
:build_production_command,
|
49
|
-
:i18n_dir, :i18n_yml_dir,
|
50
|
-
:server_render_method, :
|
50
|
+
:i18n_dir, :i18n_yml_dir, :i18n_output_format,
|
51
|
+
:server_render_method, :random_dom_id,
|
52
|
+
:same_bundle_for_client_and_server
|
51
53
|
|
52
54
|
def initialize(node_modules_location: nil, server_bundle_js_file: nil, prerender: nil,
|
53
55
|
replay_console: nil,
|
@@ -58,16 +60,17 @@ module ReactOnRails
|
|
58
60
|
generated_assets_dir: nil, webpack_generated_files: nil,
|
59
61
|
rendering_extension: nil, build_test_command: nil,
|
60
62
|
build_production_command: nil,
|
61
|
-
|
62
|
-
|
63
|
+
same_bundle_for_client_and_server: nil,
|
64
|
+
i18n_dir: nil, i18n_yml_dir: nil, i18n_output_format: nil,
|
65
|
+
random_dom_id: nil, server_render_method: nil)
|
63
66
|
self.node_modules_location = node_modules_location.present? ? node_modules_location : Rails.root
|
64
|
-
self.server_bundle_js_file = server_bundle_js_file
|
65
67
|
self.generated_assets_dirs = generated_assets_dirs
|
66
68
|
self.generated_assets_dir = generated_assets_dir
|
67
69
|
self.build_test_command = build_test_command
|
68
70
|
self.build_production_command = build_production_command
|
69
71
|
self.i18n_dir = i18n_dir
|
70
72
|
self.i18n_yml_dir = i18n_yml_dir
|
73
|
+
self.i18n_output_format = i18n_output_format
|
71
74
|
|
72
75
|
self.random_dom_id = random_dom_id
|
73
76
|
self.prerender = prerender
|
@@ -83,6 +86,8 @@ module ReactOnRails
|
|
83
86
|
self.skip_display_none = skip_display_none
|
84
87
|
|
85
88
|
# Server rendering:
|
89
|
+
self.server_bundle_js_file = server_bundle_js_file
|
90
|
+
self.same_bundle_for_client_and_server = same_bundle_for_client_and_server
|
86
91
|
self.server_renderer_pool_size = self.development_mode ? 1 : server_renderer_pool_size
|
87
92
|
self.server_renderer_timeout = server_renderer_timeout # seconds
|
88
93
|
|
@@ -90,7 +95,6 @@ module ReactOnRails
|
|
90
95
|
self.rendering_extension = rendering_extension
|
91
96
|
|
92
97
|
self.server_render_method = server_render_method
|
93
|
-
self.symlink_non_digested_assets_regex = symlink_non_digested_assets_regex
|
94
98
|
end
|
95
99
|
|
96
100
|
# on ReactOnRails
|
@@ -99,7 +103,6 @@ module ReactOnRails
|
|
99
103
|
configure_generated_assets_dirs_deprecation
|
100
104
|
configure_skip_display_none_deprecation
|
101
105
|
ensure_generated_assets_dir_present
|
102
|
-
ensure_server_bundle_js_file_has_no_path
|
103
106
|
check_i18n_directory_exists
|
104
107
|
check_i18n_yml_directory_exists
|
105
108
|
check_server_render_method_is_only_execjs
|
@@ -198,26 +201,15 @@ module ReactOnRails
|
|
198
201
|
def ensure_webpack_generated_files_exists
|
199
202
|
return unless webpack_generated_files.empty?
|
200
203
|
|
201
|
-
files = ["
|
204
|
+
files = ["manifest.json"]
|
202
205
|
files << server_bundle_js_file if server_bundle_js_file.present?
|
203
206
|
|
204
207
|
self.webpack_generated_files = files
|
205
208
|
end
|
206
209
|
|
207
|
-
def ensure_server_bundle_js_file_has_no_path
|
208
|
-
return unless server_bundle_js_file.include?(File::SEPARATOR)
|
209
|
-
|
210
|
-
assets_dir = ReactOnRails::Utils.generated_assets_full_path
|
211
|
-
self.server_bundle_js_file = File.basename(server_bundle_js_file)
|
212
|
-
|
213
|
-
Rails.logger.warn do
|
214
|
-
"[DEPRECATION] ReactOnRails: remove path from server_bundle_js_file in configuration. "\
|
215
|
-
"All generated files must go in #{assets_dir}. Using file basename #{server_bundle_js_file}"
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
210
|
def configure_skip_display_none_deprecation
|
220
211
|
return if skip_display_none.nil?
|
212
|
+
|
221
213
|
Rails.logger.warn "[DEPRECATION] ReactOnRails: remove skip_display_none from configuration."
|
222
214
|
end
|
223
215
|
end
|