react_on_rails 11.1.8 → 12.0.0.pre.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +320 -0
  3. data/.eslintignore +2 -1
  4. data/.eslintrc +30 -2
  5. data/.github/FUNDING.yml +1 -0
  6. data/.gitignore +3 -1
  7. data/.prettierignore +10 -0
  8. data/.prettierrc +23 -0
  9. data/.release-it.json +3 -0
  10. data/.rubocop.yml +37 -11
  11. data/.travis.yml +10 -20
  12. data/CHANGELOG.md +89 -3
  13. data/CONTRIBUTING.md +61 -80
  14. data/Gemfile +3 -5
  15. data/{COMM-LICENSE → REACT-ON-RAILS-PRO-LICENSE} +6 -9
  16. data/README.md +121 -71
  17. data/Rakefile +0 -7
  18. data/SUMMARY.md +10 -12
  19. data/book.json +5 -5
  20. data/docs/additional-reading/asset-pipeline.md +8 -16
  21. data/docs/additional-reading/images.md +1 -1
  22. data/docs/additional-reading/rails_view_rendering_from_inline_javascript.md +2 -1
  23. data/docs/additional-reading/react-helmet.md +30 -10
  24. data/docs/additional-reading/react-router.md +52 -75
  25. data/docs/additional-reading/server-rendering-tips.md +12 -7
  26. data/docs/additional-reading/upgrade-webpacker-v3-to-v4.md +10 -0
  27. data/docs/api/javascript-api.md +3 -3
  28. data/docs/api/redux-store-api.md +4 -2
  29. data/docs/api/view-helpers-api.md +17 -14
  30. data/docs/basics/configuration.md +64 -61
  31. data/docs/basics/deployment.md +1 -2
  32. data/docs/basics/i18n.md +44 -22
  33. data/docs/basics/installation-into-an-existing-rails-app.md +2 -2
  34. data/docs/basics/minitest-configuration.md +31 -0
  35. data/docs/basics/react-server-rendering.md +1 -1
  36. data/docs/basics/recommended-project-structure.md +1 -1
  37. data/docs/basics/{generator-functions-and-railscontext.md → render-functions-and-railscontext.md} +59 -21
  38. data/docs/basics/rspec-configuration.md +2 -2
  39. data/docs/basics/upgrading-react-on-rails.md +61 -3
  40. data/docs/basics/webpack-configuration.md +15 -1
  41. data/docs/contributor-info/errors-with-hooks.md +45 -0
  42. data/docs/contributor-info/pull-requests.md +44 -0
  43. data/docs/misc/doctrine.md +1 -1
  44. data/docs/{misc-pending → outdated}/code-splitting.md +13 -9
  45. data/docs/{additional-reading → outdated}/heroku-deployment.md +0 -6
  46. data/docs/{basics → outdated}/how-react-on-rails-works.md +3 -3
  47. data/docs/{misc-pending → outdated}/manual-installation-overview.md +5 -5
  48. data/docs/{additional-reading → outdated}/rails-assets-relative-paths.md +3 -3
  49. data/docs/{misc-pending → outdated}/rails-assets.md +4 -7
  50. data/docs/{misc → outdated}/rails3.md +0 -0
  51. data/docs/testimonials/hvmn.md +3 -3
  52. data/docs/testimonials/resortpass.md +13 -0
  53. data/docs/testimonials/testimonials.md +11 -1
  54. data/docs/tutorial.md +69 -28
  55. data/jest.config.js +4 -0
  56. data/lib/generators/react_on_rails/base_generator.rb +2 -2
  57. data/lib/generators/react_on_rails/dev_tests_generator.rb +2 -1
  58. data/lib/generators/react_on_rails/generator_helper.rb +4 -6
  59. data/lib/generators/react_on_rails/install_generator.rb +2 -0
  60. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +3 -1
  61. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-hmr +18 -0
  62. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +20 -40
  63. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +4 -8
  64. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/store/helloWorldStore.js +1 -3
  65. data/lib/react_on_rails.rb +4 -1
  66. data/lib/react_on_rails/configuration.rb +15 -23
  67. data/lib/react_on_rails/error.rb +2 -0
  68. data/lib/react_on_rails/git_utils.rb +2 -0
  69. data/lib/react_on_rails/helper.rb +111 -162
  70. data/lib/react_on_rails/json_output.rb +1 -1
  71. data/lib/react_on_rails/json_parse_error.rb +2 -0
  72. data/lib/react_on_rails/locales/base.rb +142 -0
  73. data/lib/react_on_rails/locales/to_js.rb +37 -0
  74. data/lib/react_on_rails/locales/to_json.rb +27 -0
  75. data/lib/react_on_rails/prerender_error.rb +11 -15
  76. data/lib/react_on_rails/react_component/render_options.rb +4 -0
  77. data/lib/react_on_rails/server_rendering_js_code.rb +42 -0
  78. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +71 -51
  79. data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +7 -8
  80. data/lib/react_on_rails/utils.rb +15 -20
  81. data/lib/react_on_rails/version.rb +1 -1
  82. data/lib/react_on_rails/version_checker.rb +5 -1
  83. data/lib/react_on_rails/webpacker_utils.rb +16 -2
  84. data/lib/tasks/assets.rake +5 -45
  85. data/lib/tasks/locale.rake +8 -2
  86. data/package-scripts.yml +49 -0
  87. data/package.json +41 -31
  88. data/rakelib/dummy_apps.rake +1 -9
  89. data/rakelib/example_type.rb +3 -1
  90. data/rakelib/examples.rake +3 -0
  91. data/rakelib/lint.rake +2 -7
  92. data/rakelib/node_package.rake +2 -2
  93. data/rakelib/release.rake +3 -8
  94. data/rakelib/run_rspec.rake +5 -18
  95. data/react_on_rails.gemspec +3 -5
  96. data/tsconfig.json +14 -0
  97. data/webpackConfigLoader.js +5 -4
  98. data/yarn.lock +7042 -2327
  99. metadata +39 -57
  100. data/Gemfile.rails32 +0 -74
  101. data/docs/additional-reading/babel.md +0 -5
  102. data/docs/additional-reading/hot-reloading-rails-development-asset-pipeline.md +0 -47
  103. data/docs/api/ruby-api-hot-reload-view-helpers.md +0 -44
  104. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-server +0 -12
  105. data/lib/react_on_rails/assets_precompile.rb +0 -150
  106. data/lib/react_on_rails/locales_to_js.rb +0 -136
@@ -1,6 +1,8 @@
1
1
  # React on Rails Basic Tutorial
2
2
 
3
- This tutorial guides you through setting up a new or existing Rails app with **React on Rails**, demonstrating Rails + React + Redux + Server Rendering. It is updated to 11.1.4.
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 the environment
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 5.x and node version 6+. 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.
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,15 +29,15 @@ 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
- 11\.\d+\.\d+
31
- rvm install 2.5.0 # download and install latest stable Ruby (update to exact version)
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
36
37
  gem install foreman # download and install Foreman
37
38
  ```
38
39
 
40
+ ## Create a new Ruby on Rails App
39
41
  Then we need to create a fresh Rails application with webpacker react support as following.
40
42
 
41
43
  First be sure to run `rails -v` and check you are using Rails 5.1.3 or above. If you are using an older version of Rails, you'll need to install webpacker with react per the instructions [here](https://github.com/rails/webpacker).
@@ -43,55 +45,88 @@ First be sure to run `rails -v` and check you are using Rails 5.1.3 or above. If
43
45
  ```
44
46
  cd <directory where you want to create your new Rails app>
45
47
 
46
- # any name you like for the rails app
47
- rails new test-react-on-rails --webpack=react
48
+ # Any name you like for the rails app
49
+ # Skip javascript so will add that next and get the current version
50
+ rails new --skip-sprockets -J --skip-turbolinks test-react-on-rails-v12-no-sprockets
48
51
 
49
52
  cd test-react-on-rails
50
53
  bundle
51
54
  ```
52
55
 
53
- Note: if you are installing React On Rails in an existing app or an app that uses **Rails pre 5.1.3** (*not for Rails > 5.2*), you will need to run these two commands as well:
56
+ ## Add the webpacker gem
57
+
58
+ ```
59
+ bundle add webpacker
60
+ bundle add react_on_rails
61
+ ```
62
+
63
+ ## Run the webpacker generator
54
64
 
55
65
  ```
56
66
  bundle exec rails webpacker:install
57
67
  bundle exec rails webpacker:install:react
58
68
  ```
59
69
 
60
- Add the **React On Rails** gem to your Gemfile:
70
+ Let's commit everything before installing React on Rails.
61
71
 
62
72
  ```
63
- gem 'react_on_rails', '11.1.7' # prefer exact gem version to match npm version
73
+ # Here are git commands to make a new git repo and commit everything.
74
+ # Newer versions of Rails create the git repo by default.
75
+ git add -A
76
+ git commit -m "Initial commit"
64
77
  ```
65
78
 
66
- 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.
79
+ ## Add the **React On Rails** gem to your `Gemfile`:
67
80
 
68
- Run `bundle` and commit the git repository (or `rails generate` will not work properly)
81
+ To avoid issues regarding inconsistent gem and npm versions, you should specify the exact versions
82
+ of both the gem and npm package. In other words, don't use the `^` or `~` in the version specifications.
69
83
 
84
+ ```
85
+ gem 'react_on_rails', '12.0.0' # prefer exact gem version to match npm version
86
+ ```
87
+
88
+ Note: The latest released React On Rails version is considered stable. Please use the latest
89
+ version to ensure you get all the security patches and the best support.
90
+
91
+ Run `bundle` and commit the changes.
70
92
 
71
93
  ```
72
94
  bundle
73
95
 
74
- # Here are git commands to make a new git repo and commit everything.
75
- # Newer versions of Rails create the git repo by default.
76
- git add -A
77
- git commit -m "Initial commit"
96
+ git commit -am "Added React on Rails Gem"
78
97
  ```
79
98
 
80
- 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.
99
+ 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.
100
+
101
+ Note, using `redux` is no longer recommended as the basic installer uses React Hooks.
102
+ If you want the redux install: `rails generate react_on_rails:install --redux`
81
103
 
82
104
  ```
83
105
  rails generate react_on_rails:install
84
- bundle && yarn
85
106
  ```
86
107
 
87
- and then run server with
108
+ Then run server with a static client bundle. Static means that the bundle is saved in your
109
+ public/webpack/packs directory.
88
110
 
89
111
  ```
90
112
  foreman start -f Procfile.dev
91
113
  ```
92
114
 
115
+ ## To run with the webpack-dev-server:
116
+ ```
117
+ foreman start -f Procfile.dev-hmr
118
+ ```
119
+
93
120
  Visit [http://localhost:3000/hello_world](http://localhost:3000/hello_world) and see your **React On Rails** app running!
94
- Note, foreman defaults to PORT 5000 unless you set the value of PORT in your environment or in the Procfile.
121
+
122
+ *Note, foreman may default to PORT 5000 unless you set the value of PORT in your environment or in the Procfile.*
123
+
124
+ # HMR vs. React Hot Reloading
125
+
126
+ First, check that the `hmr` option is `true` in your `config/webpacker.yml` file.
127
+
128
+ The basic setup will have HMR working with the default webpacker setup. The basic HMR will cause
129
+ a full page refresh each time you save a file. You also lose any state on your page during the refresh. Don't try to use HMR
95
130
 
96
131
  ### Custom IP & PORT setup (Cloud9 example)
97
132
 
@@ -103,7 +138,6 @@ web: rails s -p 8080 -b 0.0.0.0
103
138
 
104
139
  Then visit https://your-shared-addr.c9users.io:8080/hello_world
105
140
 
106
-
107
141
  ## RubyMine
108
142
 
109
143
  It's super important to exclude certain directories from RubyMine or else it will slow to a crawl as it tries to parse all the npm files.
@@ -218,7 +252,7 @@ end
218
252
  Then after all changes are done don't forget to commit them with git and finally you can push your app to Heroku!
219
253
 
220
254
  ```
221
- git add -a
255
+ git add -A
222
256
  git commit -m "Changes for Heroku"
223
257
  git push heroku master
224
258
  ```
@@ -231,7 +265,6 @@ heroku open
231
265
 
232
266
  and you will see your live app and you can share this URL with your friends. Congrats!
233
267
 
234
-
235
268
  ## Turning on Server Rendering
236
269
 
237
270
  You can turn on server rendering by simply changing the `prerender` option to `true`:
@@ -240,10 +273,20 @@ You can turn on server rendering by simply changing the `prerender` option to `t
240
273
  <%= react_component("HelloWorld", props: @hello_world_props, prerender: true) %>
241
274
  ```
242
275
 
276
+ If you want to test this out with HMR, then you also need to add this line to your
277
+ `config/intializers/react_on_rails.rb`
278
+
279
+ ```ruby
280
+ config.same_bundle_for_client_and_server = true
281
+ ```
282
+
283
+ More likely, you will create a different build file for server rendering. However, if you want to
284
+ use the same file from the webpack-dev-server, you'll need to add that line.
285
+
243
286
  Then push to Heroku:
244
287
 
245
288
  ```
246
- git add -a
289
+ git add -A
247
290
  git commit -m "Enable server rendering"
248
291
  git push heroku master
249
292
  ```
@@ -284,7 +327,7 @@ mv app/javascript client
284
327
 
285
328
  ## Using HMR with the rails/webpacker setup
286
329
 
287
- Start the app using `foreman start -f Procfile.dev-server`.
330
+ Start the app using `foreman start -f Procfile.dev-hmr`.
288
331
 
289
332
  When you change a JSX file and save, the browser will automatically refresh!
290
333
 
@@ -293,8 +336,6 @@ So you get some basics from HMR with no code changes. If you want to go further,
293
336
  * https://github.com/rails/webpacker/blob/master/docs/webpack-dev-server.md
294
337
  * https://webpack.js.org/configuration/dev-server/
295
338
  * https://webpack.js.org/concepts/hot-module-replacement/
296
- * https://gaearon.github.io/react-hot-loader/getstarted/
297
- * https://github.com/gaearon/react-hot-loader
298
339
 
299
340
  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.
300
341
 
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ preset: 'ts-jest/presets/js-with-ts',
3
+ testEnvironment: 'jsdom',
4
+ };
@@ -33,7 +33,7 @@ module ReactOnRails
33
33
  app/views/layouts/hello_world.html.erb
34
34
  config/initializers/react_on_rails.rb
35
35
  Procfile.dev
36
- Procfile.dev-server]
36
+ Procfile.dev-hmr]
37
37
  base_files.each { |file| copy_file("#{base_path}#{file}", file) }
38
38
  end
39
39
 
@@ -107,7 +107,7 @@ module ReactOnRails
107
107
  foreman start -f Procfile.dev
108
108
 
109
109
  - To turn on HMR, edit config/webpacker.yml and set HMR to true. Restart the rails server
110
- and bin/webpack-dev-server. Or use Procfile.dev-server.
110
+ and bin/webpack-dev-server. Or use Procfile.dev-hmr.
111
111
 
112
112
  - To server render, change this line app/views/hello_world/index.html.erb to
113
113
  `prerender: true` to see server rendering (right click on page and select "view source").
@@ -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": "yarn link react-on-rails",
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
- # rubocop:disable Layout/IndentHeredoc
19
- <<-MSG
20
- #{file} was not found.
21
- Please add the following content to your #{file} file:
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
@@ -4,4 +4,6 @@ web: rails s -p 3000
4
4
  # Next line runs a watch process with webpack to compile the changed files.
5
5
  # When making frequent changes to client side assets, you will prefer building webpack assets
6
6
  # upon saving rather than when you refresh your browser page.
7
- client: sh -c 'rm -rf public/packs/* || true && bundle exec rake react_on_rails:locale && bin/webpack -w'
7
+ # Note, if using React on Rails localization you will need to run
8
+ # `bundle exec rake react_on_rails:locale` before you run bin/webpack
9
+ client: sh -c 'rm -rf public/packs/* || true && bin/webpack -w'
@@ -0,0 +1,18 @@
1
+ web: rails s -p 3000
2
+
3
+ # Note, hot and live reloading don't work with the default generator setup on
4
+ # top of the rails/webpacker Webpack config with server rendering.
5
+ # If you have server rendering enabled (prerender is true), you either need to
6
+ # a. Skip using the webpack-dev-server. bin/webpack --watch is typically
7
+ fast enough.
8
+ # b. See the React on Rails README for a link to documentation for how to setup
9
+ # SSR with HMR and React hot loading
10
+ # Otherwise, you will have an error. If you want HMR and Server Rendering, see
11
+ # the example in the https://github.com/shakacode/react-webpack-rails-tutorial
12
+ web: rails s -p 3000
13
+
14
+ # Run the hot reload server for client development
15
+ webpack-dev-server: bin/webpack-dev-server
16
+
17
+ # Keep the JS fresh for server rendering. Remove if not server rendering
18
+ rails-server-assets: SERVER_BUNDLE_ONLY=yes bin/webpack --watch
@@ -1,45 +1,25 @@
1
1
  import PropTypes from 'prop-types';
2
- import React from 'react';
2
+ import React, { useState } from 'react';
3
3
 
4
- export default class HelloWorld extends React.Component {
5
- static propTypes = {
6
- name: PropTypes.string.isRequired, // this is passed from the Rails view
7
- };
4
+ const HelloWorld = (props) => {
5
+ const [name, setName] = useState(props.name);
8
6
 
9
- /**
10
- * @param props - Comes from your rails view.
11
- */
12
- constructor(props) {
13
- super(props);
7
+ return (
8
+ <div>
9
+ <h3>Hello, {name}!</h3>
10
+ <hr />
11
+ <form>
12
+ <label htmlFor="name">
13
+ Say hello to:
14
+ <input id="name" type="text" value={name} onChange={(e) => setName(e.target.value)} />
15
+ </label>
16
+ </form>
17
+ </div>
18
+ );
19
+ };
14
20
 
15
- // How to set initial state in ES6 class syntax
16
- // https://reactjs.org/docs/state-and-lifecycle.html#adding-local-state-to-a-class
17
- this.state = { name: this.props.name };
18
- }
21
+ HelloWorld.propTypes = {
22
+ name: PropTypes.string.isRequired, // this is passed from the Rails view
23
+ };
19
24
 
20
- updateName = (name) => {
21
- this.setState({ name });
22
- };
23
-
24
- render() {
25
- return (
26
- <div>
27
- <h3>
28
- Hello, {this.state.name}!
29
- </h3>
30
- <hr />
31
- <form >
32
- <label htmlFor="name">
33
- Say hello to:
34
- </label>
35
- <input
36
- id="name"
37
- type="text"
38
- value={this.state.name}
39
- onChange={(e) => this.updateName(e.target.value)}
40
- />
41
- </form>
42
- </div>
43
- );
44
- }
45
- }
25
+ export default HelloWorld;
@@ -4,19 +4,15 @@ import React from 'react';
4
4
  const HelloWorld = ({ name, updateName }) => (
5
5
  <div>
6
6
  <h3>
7
- Hello, {name}!
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;
@@ -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/locales_to_js"
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: false,
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, :symlink_non_digested_assets_regex, :random_dom_id
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
- i18n_dir: nil, i18n_yml_dir: nil, random_dom_id: nil,
62
- server_render_method: nil, symlink_non_digested_assets_regex: nil)
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 = ["hello-world-bundle.js"]
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