react_on_rails 12.0.1 → 12.0.5.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 +1 -1
- data/.eslintrc +0 -1
- data/.github/workflows/lint-js-and-ruby.yml +53 -0
- data/.github/workflows/main.yml +178 -0
- data/.github/workflows/package-js-tests.yml +35 -0
- data/.github/workflows/rspec-package-specs.yml +45 -0
- data/.rubocop.yml +15 -44
- data/.travis.yml +3 -1
- data/CHANGELOG.md +20 -1
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +1 -33
- data/Gemfile.development_dependencies +50 -0
- data/NEWS.md +5 -0
- data/README.md +26 -20
- data/SUMMARY.md +1 -1
- data/docs/additional-reading/recommended-project-structure.md +69 -0
- data/docs/basics/client-vs-server-rendering.md +2 -0
- data/docs/basics/hmr-and-hot-reloading-with-the-webpack-dev-server.md +64 -9
- data/docs/basics/installation-into-an-existing-rails-app.md +11 -4
- data/docs/basics/react-server-rendering.md +8 -5
- data/docs/basics/upgrading-react-on-rails.md +37 -14
- data/docs/basics/webpack-configuration.md +12 -18
- data/docs/misc/doctrine.md +0 -1
- data/docs/outdated/code-splitting.md +2 -2
- data/docs/tutorial.md +19 -21
- data/lib/generators/react_on_rails/base_generator.rb +8 -1
- data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +4 -1
- data/lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb +1 -1
- data/lib/react_on_rails/configuration.rb +2 -0
- data/lib/react_on_rails/git_utils.rb +3 -3
- data/lib/react_on_rails/helper.rb +10 -9
- data/lib/react_on_rails/locales/base.rb +3 -3
- data/lib/react_on_rails/locales/to_js.rb +0 -4
- data/lib/react_on_rails/locales/to_json.rb +0 -4
- data/lib/react_on_rails/prerender_error.rb +1 -1
- data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +6 -6
- data/lib/react_on_rails/test_helper.rb +2 -0
- data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +1 -1
- data/lib/react_on_rails/utils.rb +8 -2
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/react_on_rails/webpacker_utils.rb +4 -4
- data/lib/tasks/assets.rake +6 -6
- data/package.json +1 -1
- data/rakelib/docker.rake +0 -5
- data/rakelib/lint.rake +3 -9
- data/rakelib/release.rake +9 -11
- data/rakelib/run_rspec.rake +10 -11
- data/rakelib/task_helpers.rb +2 -3
- data/react_on_rails.gemspec +3 -17
- metadata +16 -194
- data/docs/additional-reading/webpack-dev-server.md +0 -15
- data/docs/basics/recommended-project-structure.md +0 -77
- data/ruby-lint.yml +0 -25
@@ -1,13 +1,13 @@
|
|
1
1
|
# Upgrading React on Rails
|
2
2
|
|
3
3
|
## Need Help Migrating?
|
4
|
-
If you would like help in migrating between React on Rails versions or help with implementing server rendering, please contact [justin@shakacode.com](mailto:justin@shakacode.com) for information about our [
|
4
|
+
If you would like help in migrating between React on Rails versions or help with implementing server rendering, please contact [justin@shakacode.com](mailto:justin@shakacode.com) for more information about our [React on Rails Pro Support](https://www.shakacode.com/react-on-rails-pro).
|
5
5
|
|
6
|
-
We specialize in helping companies to quickly and efficiently
|
6
|
+
We specialize in helping companies to quickly and efficiently upgrade. The older versions use the Rails asset pipeline to package client assets. The current and recommended way is to use Webpack 4+ for asset preparation. You may also need help migrating from the `rails/webpacker`'s Webpack configuration to a better setup ready for Server Side Rendering.
|
7
7
|
|
8
8
|
## Upgrading to v12
|
9
9
|
### Recent versions
|
10
|
-
Make sure that you are on a relatively more recent version of rails and webpacker.
|
10
|
+
Make sure that you are on a relatively more recent version of rails and webpacker. Yes, the [rails/webpacker](https://github.com/rails/webpacker) gem is required!
|
11
11
|
v12 is tested on Rails 6. It should work on Rails v5. If you're on any older version,
|
12
12
|
and v12 doesn't work, please file an issue.
|
13
13
|
|
@@ -28,20 +28,43 @@ return a React component, or you are registering a React component defined by a
|
|
28
28
|
Please see [Render-Functions and the Rails Context](./render-functions-and-railscontext.md) for
|
29
29
|
more information on what a Render-Function is.
|
30
30
|
|
31
|
-
#####
|
31
|
+
##### Update required for registered functions taking exactly 2 params.
|
32
32
|
|
33
|
-
Registered Objects are of the following
|
34
|
-
1.
|
33
|
+
Registered Objects are of the following type:
|
34
|
+
1. **Function that takes only zero or one params and you return a React Element**, often JSX. If the function takes zero or one params, there is **no migration needed** for that function.
|
35
35
|
```js
|
36
36
|
export default (props) => <Component {...props} />;
|
37
|
-
```
|
38
|
-
|
39
|
-
|
37
|
+
```
|
38
|
+
|
39
|
+
2. **Function that takes only zero or one params and you return an Object (_not a React Element_)**. If the function takes zero or one params, **you need to add one or two unused params so you have exactly 2 params** and then that function will be treated as a render function and it can return an Object rather than a React element. If you don't do this, you'll see this obscure error message:
|
40
|
+
|
41
|
+
```
|
42
|
+
[SERVER] message: Objects are not valid as a React child (found: object with keys {renderedHtml}). If you meant to render a collection of children, use an array instead.
|
43
|
+
in YourComponentRenderFunction
|
44
|
+
```
|
45
|
+
|
46
|
+
So look in YourComponentRenderFunction and do this change
|
47
|
+
|
48
|
+
```js
|
49
|
+
export default (props) => { renderedHTML: getRenderedHTML };
|
50
|
+
```
|
51
|
+
|
52
|
+
To have exactly 2 arguments:
|
53
|
+
|
54
|
+
```js
|
55
|
+
export default (props, _railsContext) => { renderedHTML: getRenderedHTML };
|
56
|
+
```
|
57
|
+
|
58
|
+
3. Function that takes **2 params** and returns **a React function or class component**. _Migration is needed as the older syntax returned a React Element._
|
59
|
+
A function component is a function that takes zero or one params and returns a React Element, like JSX. The correct syntax
|
60
|
+
looks like:
|
40
61
|
```js
|
41
|
-
export default (props,
|
62
|
+
export default (props, railsContext) => () => <Component {{...props, railsContext}} />;
|
42
63
|
```
|
43
|
-
Note, you cannot return a React Element (JSX).
|
44
|
-
|
64
|
+
Note, you cannot return a React Element (JSX). See below for the migration steps. If your function that took **two params returned
|
65
|
+
an Object**, then no migration is required.
|
66
|
+
4. Function that takes **3 params** and uses the 3rd param, `domNodeId`, to call `ReactDOM.hydrate`. If the function takes 3 params, there is **no migration needed** for that function.
|
67
|
+
5. ES6 or ES5 class. There is **no migration needed**.
|
45
68
|
|
46
69
|
Previously, with case number 2, you could return a React Element.
|
47
70
|
|
@@ -51,7 +74,7 @@ The fix is simple. Here is an example of the change you'll do:
|
|
51
74
|
|
52
75
|
##### Broken, as this function takes two params and it returns a React Element from a JSX Literal
|
53
76
|
```js
|
54
|
-
export default (props,
|
77
|
+
export default (props, railsContext) => <Component {{...props, railsContext} />;
|
55
78
|
```
|
56
79
|
|
57
80
|
If you make this mistake, you'll get this warning
|
@@ -77,7 +100,7 @@ wrapper such that you're returning a function rather than a React Element, then:
|
|
77
100
|
|
78
101
|
## Upgrading rails/webpacker from v3 to v4
|
79
102
|
### Custom Webpack build file
|
80
|
-
The default value for `extract_css` is **false** in `config/webpack.yml`. Custom webpack builds should set this value to true or else no CSS link tags are generated. You have a custom webpack build if you are not using [rails/webpacker](https://github.com/rails/webpacker to setup your Webpack configuration.
|
103
|
+
The default value for `extract_css` is **false** in `config/webpack.yml`. Custom webpack builds should set this value to true or else no CSS link tags are generated. You have a custom webpack build if you are not using [rails/webpacker](https://github.com/rails/webpacker) to setup your Webpack configuration.
|
81
104
|
|
82
105
|
```yml
|
83
106
|
default: &default
|
@@ -6,8 +6,13 @@
|
|
6
6
|
|
7
7
|
[rails/webpacker](https://github.com/rails/webpacker) is the Ruby gem that mainly gives us 2 things:
|
8
8
|
|
9
|
-
1. View helpers for placing the
|
10
|
-
2. A layer of abstraction on top of Webpack customization.
|
9
|
+
1. View helpers for placing the webpack bundles on your Rails views. React on Rails depends on these view helpers.
|
10
|
+
2. A layer of abstraction on top of Webpack customization. The base setup works great for the client side webpack configuration.
|
11
|
+
|
12
|
+
To get a deeper understanding of `rails/webpacker`, watch [RailsConf 2020 CE - Webpacker, It-Just-Works, But How? by Justin Gordon](https://youtu.be/sJLoOpc5LD8)
|
13
|
+
|
14
|
+
Per the example repo [shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh),
|
15
|
+
you should consider keeping your codebase mostly consistent with the defaults for [rails/webpacker](https://github.com/rails/webpacker).
|
11
16
|
|
12
17
|
# React on Rails
|
13
18
|
|
@@ -15,15 +20,15 @@ Version 9 of React on Rails added support for the rails/webpacker view helpers s
|
|
15
20
|
|
16
21
|
A key decision in your use React on Rails is whether you go with the rails/webpacker default setup or the traditional React on Rails setup of putting all your client side files under the `/client` directory. While there are technically 2 independent choices involved, the directory structure and the mechanism of Webpack configuration, for simplicity sake we'll assume that these choices go together.
|
17
22
|
|
18
|
-
## Option 1:
|
23
|
+
## Option 1: Default Generator Setup: rails/webpacker app/javascript
|
19
24
|
|
20
|
-
|
25
|
+
Typical rails/webpacker apps have a standard directory structure as documented [here](https://github.com/rails/webpacker/blob/master/docs/folder-structure.md). If you follow the steps in the the [basic tutorial](../../docs/tutorial.md), you will see this pattern in action. In order to customize the Webpack configuration, you need to consult with the [rails/webpacker Webpack configuration](https://github.com/rails/webpacker/blob/master/docs/webpack.md).
|
21
26
|
|
22
|
-
The
|
27
|
+
The *advantage* of using rails/webpacker to configure Webpack is that there is very little code needed to get started and you don't need to understand really anything about Webpack customization.
|
23
28
|
|
24
|
-
|
29
|
+
## Option 2: Traditional React on Rails using the /client directory
|
25
30
|
|
26
|
-
|
31
|
+
Until version 9, all React on Rails apps used the `/client` directory for configuring React on Rails in terms of the configuration of Webpack and location of your JavaScript and Webpack files, including the node_modules directory. Version 9 changed the default to `/` for the `node_modules` location using this value in `config/initializers/react_on_rails.rb`: `config.node_modules_location`.
|
27
32
|
|
28
33
|
You can access values in the `config/webpacker.yml`
|
29
34
|
|
@@ -36,15 +41,4 @@ You will want consider using some of the same values set in these files:
|
|
36
41
|
* https://github.com/rails/webpacker/blob/master/package/environments/base.js
|
37
42
|
* https://github.com/rails/webpacker/blob/master/package/environments/development.js
|
38
43
|
|
39
|
-
**Note**, if your node_modules directory is not at the top level of the Rails project, then you will need to set the
|
40
|
-
ENV value of WEBPACKER_CONFIG to the location of the `config/webpacker.yml` file per [rails/webpacker PR 2561](https://github.com/rails/webpacker/pull/2561).
|
41
|
-
|
42
|
-
## Option 2: Default Generator Setup: rails/webpacker app/javascript
|
43
|
-
|
44
|
-
Typical rails/webpacker apps have a standard directory structure as documented [here](https://github.com/rails/webpacker/blob/master/docs/folder-structure.md). If you follow the steps in the the [basic tutorial](../../docs/tutorial.md), you will see this pattern in action. In order to customize the Webpack configuration, you need to consult with the [rails/webpacker Webpack configuration](https://github.com/rails/webpacker/blob/master/docs/webpack.md).
|
45
|
-
|
46
|
-
The *advantage* of using rails/webpacker to configure Webpack is that there is very little code needed to get started and you don't need to understand really anything about Webpack customization. The *big disadvantage* to this is that you will need to learn the ins and outs of the [rails/webpacker way to customize Webpack](https://github.com/rails/webpacker/blob/master/docs/webpack.md) which differs from the plain [Webpack way](https://webpack.js.org/).
|
47
44
|
|
48
|
-
You can find more details on this topic in [Recommended Project Structure](./recommended-project-structure.md).
|
49
|
-
|
50
|
-
See [Issue 982: Tutorial Generating Correct Project Structure?](https://github.com/shakacode/react_on_rails/issues/982) to discuss this issue.
|
data/docs/misc/doctrine.md
CHANGED
@@ -25,7 +25,6 @@ The React on Rails setup provides several key components related to front-end de
|
|
25
25
|
* React on Rails has taken the hard work out of figuring out the JavaScript tooling that works best with Rails. Not only could you spend lots of time researching different tooling, but then you'd have to figure out how to splice it all together. This is where a lot of "JavaScript fatigue" comes from. The following keep the code clean and consistent:
|
26
26
|
* [Style Guide](../coding-style/style.md)
|
27
27
|
* [linters](../contributor-info/linters.md)
|
28
|
-
* [Recommended Project Structure](../basics/recommended-project-structure.md)
|
29
28
|
|
30
29
|
We're big believers in this quote from the Rails Doctrine:
|
31
30
|
|
@@ -117,8 +117,8 @@ There's an implemented example of code splitting in the `spec/dummy` folder of t
|
|
117
117
|
|
118
118
|
See:
|
119
119
|
|
120
|
-
- [spec/dummy/client/app/startup/
|
121
|
-
- [spec/dummy/client/app/
|
120
|
+
- [spec/dummy/client/app/startup/client-bundle.js](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/client-bundle.js)
|
121
|
+
- [spec/dummy/client/app/packs/server-bundle.js](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/packs/server-bundle.js)
|
122
122
|
- [spec/dummy/client/app/startup/DeferredRenderAppClient](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/DeferredRenderAppClient.jsx)<-- Code splitting implemented here
|
123
123
|
- [spec/dummy/client/app/startup/DeferredRenderAppServer.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/DeferredRenderAppServer.jsx)
|
124
124
|
- [spec/dummy/client/app/components/DeferredRender.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/components/DeferredRender.jsx)
|
data/docs/tutorial.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# React on Rails Basic Tutorial
|
2
2
|
|
3
|
+
-----
|
4
|
+
|
5
|
+
**November 11, 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`. This file will be update shortly. Most of it is still relevant.
|
6
|
+
|
7
|
+
-----
|
8
|
+
|
3
9
|
*Updated for Ruby 2.7.1, Rails 6.0.3.1, and React on Rails v12.0.0*
|
4
10
|
|
5
11
|
This tutorial guides you through setting up a new or existing Rails app with **React on Rails**, demonstrating Rails + React + Redux + Server Rendering.
|
@@ -53,11 +59,21 @@ cd test-react-on-rails
|
|
53
59
|
bundle
|
54
60
|
```
|
55
61
|
|
56
|
-
## Add the webpacker
|
62
|
+
## Add the webpacker and react_on_rails gems
|
63
|
+
To avoid issues regarding inconsistent gem and npm versions, you should specify the exact versions
|
64
|
+
of both the gem and npm package. In other words, don't use the `^` or `~` in the version specifications.
|
65
|
+
_Use the latest version for react_on_rails._
|
57
66
|
|
58
67
|
```
|
68
|
+
gem 'react_on_rails', '12.0.4' # prefer exact gem version to match npm version
|
69
|
+
```
|
70
|
+
|
71
|
+
Note: The latest released React On Rails version is considered stable. Please use the latest
|
72
|
+
version to ensure you get all the security patches and the best support.
|
73
|
+
|
74
|
+
```bash
|
59
75
|
bundle add webpacker
|
60
|
-
bundle add react_on_rails
|
76
|
+
bundle add react_on_rails --version=12.0.4 --strict
|
61
77
|
```
|
62
78
|
|
63
79
|
## Run the webpacker generator
|
@@ -76,25 +92,7 @@ git add -A
|
|
76
92
|
git commit -m "Initial commit"
|
77
93
|
```
|
78
94
|
|
79
|
-
##
|
80
|
-
|
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.
|
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.
|
92
|
-
|
93
|
-
```
|
94
|
-
bundle
|
95
|
-
|
96
|
-
git commit -am "Added React on Rails Gem"
|
97
|
-
```
|
95
|
+
## Run the React on Rails Generator
|
98
96
|
|
99
97
|
Install React on Rails: `rails generate react_on_rails:install`. You need to first git commit your files before running the generator, or else it will generate an error.
|
100
98
|
|
@@ -43,7 +43,14 @@ module ReactOnRails
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def add_yarn_dependencies
|
46
|
-
|
46
|
+
major_minor_patch_only = /\A\d+\.\d+\.\d+\z/.freeze
|
47
|
+
if ReactOnRails::VERSION.match?(major_minor_patch_only)
|
48
|
+
run "yarn add react-on-rails@#{ReactOnRails::VERSION} --exact"
|
49
|
+
else
|
50
|
+
# otherwise add latest
|
51
|
+
puts "Adding the lastest react-on-rails NPM module. Double check this is correct in package.json"
|
52
|
+
run "yarn add react-on-rails --exact"
|
53
|
+
end
|
47
54
|
end
|
48
55
|
|
49
56
|
def append_to_spec_rails_helper
|
@@ -15,7 +15,10 @@ require "capybara/rspec"
|
|
15
15
|
require "capybara/rails"
|
16
16
|
Capybara.javascript_driver = :selenium_chrome
|
17
17
|
Capybara.register_driver :selenium_chrome do |app|
|
18
|
-
|
18
|
+
options = Selenium::WebDriver::Chrome::Options.new
|
19
|
+
options.add_argument("--headless")
|
20
|
+
options.add_argument("--disable-gpu")
|
21
|
+
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
|
19
22
|
end
|
20
23
|
|
21
24
|
# Requires supporting ruby files with custom matchers and macros, etc, in
|
@@ -53,6 +53,7 @@ module ReactOnRails
|
|
53
53
|
:server_render_method, :random_dom_id,
|
54
54
|
:same_bundle_for_client_and_server
|
55
55
|
|
56
|
+
# rubocop:disable Metrics/AbcSize
|
56
57
|
def initialize(node_modules_location: nil, server_bundle_js_file: nil, prerender: nil,
|
57
58
|
replay_console: nil,
|
58
59
|
trace: nil, development_mode: nil,
|
@@ -98,6 +99,7 @@ module ReactOnRails
|
|
98
99
|
|
99
100
|
self.server_render_method = server_render_method
|
100
101
|
end
|
102
|
+
# rubocop:enable Metrics/AbcSize
|
101
103
|
|
102
104
|
# on ReactOnRails
|
103
105
|
def setup_config_values
|
@@ -10,10 +10,10 @@ module ReactOnRails
|
|
10
10
|
status = `git status --porcelain`
|
11
11
|
return false if $CHILD_STATUS.success? && status.empty?
|
12
12
|
|
13
|
-
error = if
|
14
|
-
"You do not have Git installed. Please install Git, and commit your changes before continuing"
|
15
|
-
else
|
13
|
+
error = if $CHILD_STATUS.success?
|
16
14
|
"You have uncommitted code. Please commit or stash your changes before continuing"
|
15
|
+
else
|
16
|
+
"You do not have Git installed. Please install Git, and commit your changes before continuing"
|
17
17
|
end
|
18
18
|
message_handler.add_error(error)
|
19
19
|
true
|
@@ -32,8 +32,8 @@ module ReactOnRails
|
|
32
32
|
# Exposing the react_component_name is necessary to both a plain ReactComponent as well as
|
33
33
|
# a generator:
|
34
34
|
# See README.md for how to "register" your react components.
|
35
|
-
# See spec/dummy/client/app/
|
36
|
-
# spec/dummy/client/app/
|
35
|
+
# See spec/dummy/client/app/packs/server-bundle.js and
|
36
|
+
# spec/dummy/client/app/packs/client-bundle.js for examples of this.
|
37
37
|
#
|
38
38
|
# options:
|
39
39
|
# props: Ruby Hash or JSON string which contains the properties to pass to the react object. Do
|
@@ -57,14 +57,15 @@ module ReactOnRails
|
|
57
57
|
server_rendered_html = internal_result[:result]["html"]
|
58
58
|
console_script = internal_result[:result]["consoleReplayScript"]
|
59
59
|
|
60
|
-
|
60
|
+
case server_rendered_html
|
61
|
+
when String
|
61
62
|
build_react_component_result_for_server_rendered_string(
|
62
63
|
server_rendered_html: server_rendered_html,
|
63
64
|
component_specification_tag: internal_result[:tag],
|
64
65
|
console_script: console_script,
|
65
66
|
render_options: internal_result[:render_options]
|
66
67
|
)
|
67
|
-
|
68
|
+
when Hash
|
68
69
|
msg = <<~MSG
|
69
70
|
Use react_component_hash (not react_component) to return a Hash to your ruby view code. See
|
70
71
|
https://github.com/shakacode/react_on_rails/blob/master/spec/dummy/client/app/startup/ReactHelmetServerApp.jsx
|
@@ -169,7 +170,7 @@ module ReactOnRails
|
|
169
170
|
def redux_store_hydration_data
|
170
171
|
return if @registered_stores_defer_render.blank?
|
171
172
|
|
172
|
-
@registered_stores_defer_render.reduce(""
|
173
|
+
@registered_stores_defer_render.reduce(+"") do |accum, redux_store_data|
|
173
174
|
accum << render_redux_store_data(redux_store_data)
|
174
175
|
end.html_safe
|
175
176
|
end
|
@@ -243,7 +244,7 @@ module ReactOnRails
|
|
243
244
|
# second parameter passed to both component and store Render-Functions.
|
244
245
|
# This method can be called from views and from the controller, as `helpers.rails_context`
|
245
246
|
#
|
246
|
-
# rubocop:disable Metrics/AbcSize
|
247
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
247
248
|
def rails_context(server_side: true)
|
248
249
|
# ALERT: Keep in sync with node_package/src/types/index.ts for the properties of RailsContext
|
249
250
|
@rails_context ||= begin
|
@@ -291,7 +292,7 @@ module ReactOnRails
|
|
291
292
|
|
292
293
|
@rails_context.merge(serverSide: server_side)
|
293
294
|
end
|
294
|
-
# rubocop:enable Metrics/AbcSize
|
295
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
295
296
|
|
296
297
|
private
|
297
298
|
|
@@ -486,13 +487,13 @@ module ReactOnRails
|
|
486
487
|
end
|
487
488
|
|
488
489
|
def initialize_redux_stores
|
489
|
-
result =
|
490
|
+
result = +<<-JS
|
490
491
|
ReactOnRails.clearHydratedStores();
|
491
492
|
JS
|
492
493
|
|
493
494
|
return result unless @registered_stores.present? || @registered_stores_defer_render.present?
|
494
495
|
|
495
|
-
declarations = "var reduxProps, store, storeGenerator;\n"
|
496
|
+
declarations = +"var reduxProps, store, storeGenerator;\n"
|
496
497
|
all_stores = (@registered_stores || []) + (@registered_stores_defer_render || [])
|
497
498
|
|
498
499
|
result << all_stores.each_with_object(declarations) do |redux_store_data, memo|
|
@@ -32,12 +32,12 @@ module ReactOnRails
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def exist_files
|
35
|
-
@exist_files ||= files.select
|
35
|
+
@exist_files ||= files.select { |file| File.exist?(file) }
|
36
36
|
end
|
37
37
|
|
38
38
|
def files_are_outdated
|
39
|
-
latest_yml = locale_files.map
|
40
|
-
earliest = exist_files.map
|
39
|
+
latest_yml = locale_files.map { |file| File.mtime(file) }.max
|
40
|
+
earliest = exist_files.map { |file| File.mtime(file) }.min
|
41
41
|
latest_yml > earliest
|
42
42
|
end
|
43
43
|
|
@@ -46,7 +46,7 @@ module ReactOnRails
|
|
46
46
|
private
|
47
47
|
|
48
48
|
def calc_message(component_name, console_messages, err, js_code, props)
|
49
|
-
message = "ERROR in SERVER PRERENDERING\n"
|
49
|
+
message = +"ERROR in SERVER PRERENDERING\n"
|
50
50
|
if err
|
51
51
|
message << <<~MSG
|
52
52
|
Encountered error: \"#{err}\"
|
@@ -47,6 +47,7 @@ module ReactOnRails
|
|
47
47
|
# Note, js_code does not have to be based on React.
|
48
48
|
# js_code MUST RETURN json stringify Object
|
49
49
|
# Calling code will probably call 'html_safe' on return value before rendering to the view.
|
50
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
50
51
|
def exec_server_render_js(js_code, render_options, js_evaluator = nil)
|
51
52
|
js_evaluator ||= self
|
52
53
|
if render_options.trace
|
@@ -67,16 +68,15 @@ module ReactOnRails
|
|
67
68
|
console_script = result["consoleReplayScript"]
|
68
69
|
console_script_lines = console_script.split("\n")
|
69
70
|
console_script_lines = console_script_lines[2..-2]
|
70
|
-
re = /console\.(log|error)\.apply\(console, \["\[SERVER\] (?<msg>.*)"\]\);/
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
Rails.logger.info { "[react_on_rails] #{match[:msg]}" } if match
|
75
|
-
end
|
71
|
+
re = /console\.(?:log|error)\.apply\(console, \["\[SERVER\] (?<msg>.*)"\]\);/
|
72
|
+
console_script_lines&.each do |line|
|
73
|
+
match = re.match(line)
|
74
|
+
Rails.logger.info { "[react_on_rails] #{match[:msg]}" } if match
|
76
75
|
end
|
77
76
|
end
|
78
77
|
result
|
79
78
|
end
|
79
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
80
80
|
|
81
81
|
def trace_js_code_used(msg, js_code, file_name = "tmp/server-generated.js", force: false)
|
82
82
|
return unless ReactOnRails.configuration.trace || force
|
@@ -52,6 +52,7 @@ module ReactOnRails
|
|
52
52
|
# don't provide one.
|
53
53
|
# webpack_generated_files List of files to check for up-to-date-status, defaulting to
|
54
54
|
# webpack_generated_files in your configuration
|
55
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
55
56
|
def self.ensure_assets_compiled(webpack_assets_status_checker: nil,
|
56
57
|
webpack_assets_compiler: nil,
|
57
58
|
source_path: nil,
|
@@ -96,4 +97,5 @@ module ReactOnRails
|
|
96
97
|
).call
|
97
98
|
end
|
98
99
|
end
|
100
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
99
101
|
end
|