react_on_rails 11.0.3 → 11.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +11 -1
- data/CONTRIBUTING.md +7 -8
- data/PROJECTS.md +7 -1
- data/README.md +43 -0
- data/Rakefile +4 -1
- data/docs/additional-reading/rspec-configuration.md +5 -5
- data/docs/basics/configuration.md +2 -1
- data/lib/react_on_rails/configuration.rb +47 -13
- data/lib/react_on_rails/react_on_rails_helper.rb +27 -7
- data/lib/react_on_rails/server_rendering_pool.rb +1 -15
- data/lib/react_on_rails/test_helper.rb +8 -7
- data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +5 -5
- data/lib/react_on_rails/utils.rb +18 -5
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/react_on_rails/webpacker_utils.rb +10 -7
- data/package.json +1 -1
- data/react_on_rails.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55cdca62eaf8c15553635f8255d102728e030761
|
4
|
+
data.tar.gz: c72e8903805accdf9cf3964162dfdfe4254380ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74f8c628d2e4ef60422d383483d2828fc70e773ab85a88f2d44a8a43a357cfd61b3213e9016aefe3963371d965b70fbca3f2599f29037d09f2d3218c08cc9d06
|
7
|
+
data.tar.gz: 8f34bcfa66613559f97ffaa766e676bdd6df69484eb21d1e1f1d34eeaba972910eee058e7347c84e252bee8f87b44e5282d9ae896d467d05c92ddba03a00e3cd
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -10,6 +10,15 @@ Changes since last non-beta release.
|
|
10
10
|
|
11
11
|
*Please add entries here for your pull requests that are not yet released.*
|
12
12
|
|
13
|
+
### [11.0.4] - 2018-05-3
|
14
|
+
|
15
|
+
#### Changed
|
16
|
+
- Throw if configuration.generated_assets_dir specified, and using webpacker, and if that doesn't match the public_output_path. Otherwise, warn if generated_assets_dir is specified
|
17
|
+
- Fix the setup for tests for spec/dummy so they automatically rebuild by correctly setting the source_path in the webpacker.yml
|
18
|
+
- Updated documentation for the testing setup.
|
19
|
+
- Above in [PR 1072](https://github.com/shakacode/react_on_rails/pull/1072) by [justin808](https://github.com/justin808).
|
20
|
+
- `react_component_hash` has implicit `prerender: true` because it makes no sense to have react_component_hash not use prerrender. Improved docs on `react_component_hash`. Also, fixed issue where checking gem existence. [PR 1077](https://github.com/shakacode/react_on_rails/pull/1077) by [justin808](https://github.com/justin808).
|
21
|
+
|
13
22
|
### [11.0.3] - 2018-04-24
|
14
23
|
|
15
24
|
#### Fixed
|
@@ -744,7 +753,8 @@ Best done with Object destructing:
|
|
744
753
|
##### Fixed
|
745
754
|
- Fix several generator related issues.
|
746
755
|
|
747
|
-
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/11.0.
|
756
|
+
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/11.0.4...master
|
757
|
+
[11.0.4]: https://github.com/shakacode/react_on_rails/compare/11.0.3...11.0.4
|
748
758
|
[11.0.3]: https://github.com/shakacode/react_on_rails/compare/11.0.2...11.0.3
|
749
759
|
[11.0.2]: https://github.com/shakacode/react_on_rails/compare/11.0.1...11.0.2
|
750
760
|
[11.0.1]: https://github.com/shakacode/react_on_rails/compare/11.0.0...11.0.1
|
data/CONTRIBUTING.md
CHANGED
@@ -75,7 +75,7 @@ It's critical to configure your IDE/editor to ignore certain directories. Otherw
|
|
75
75
|
# Configuring your test app to use your local fork
|
76
76
|
You can test the `react-on-rails` gem using your own external test app or the gem's internal `spec/dummy` app. The `spec/dummy` app is an example of the various setup techniques you can use with the gem.
|
77
77
|
```
|
78
|
-
├──
|
78
|
+
├── test_app
|
79
79
|
| └── client
|
80
80
|
└── react_on_rails
|
81
81
|
└── spec
|
@@ -98,21 +98,20 @@ In addition to testing the Ruby parts out, you can also test the node package pa
|
|
98
98
|
cd react_on_rails/
|
99
99
|
yarn
|
100
100
|
yarn run build
|
101
|
+
yarn install-react-on-rails
|
101
102
|
```
|
102
103
|
|
103
|
-
Install the local package by using
|
104
|
+
Install the local package by using yarn link, like this:
|
104
105
|
```sh
|
105
|
-
cd
|
106
|
-
|
106
|
+
cd spec/dummy
|
107
|
+
yarn
|
107
108
|
```
|
108
|
-
_Note: You must use npm here till yarn stops preferring cached packages over local. see [issue #2649](https://github.com/yarnpkg/yarn/issues/2649)_
|
109
109
|
|
110
|
-
|
110
|
+
Note, yarn will run the `postinstall` script of `spec/dummy/client` which runs `yarn link` to setup a sym link to the parent package.
|
111
111
|
|
112
112
|
#### Example: Testing NPM changes with the dummy app
|
113
113
|
1. Add `console.log('Hello!')` [here](https://github.com/shakacode/react_on_rails/blob/master/node_package/src/clientStartup.js#L181) in `react_on_rails/node_package/src/clientStartup.js` to confirm we're getting an update to the node package.
|
114
|
-
2.
|
115
|
-
3. Refresh the browser if the server is already running or start the server using `foreman start` from `react_on_rails/spec/dummy` and navigate to `http://localhost:5000/`. You will now see the `Hello!` message printed in the browser's console.
|
114
|
+
2. Refresh the browser if the server is already running or start the server using `foreman start` from `react_on_rails/spec/dummy` and navigate to `http://localhost:5000/`. You will now see the `Hello!` message printed in the browser's console.
|
116
115
|
|
117
116
|
_Note: running `npm i` automatically builds the npm package before installing. However, when using yarn you will need to run `yarn run build` in the root directory before the install script. This will be updated when [yarn issue #2649](https://github.com/yarnpkg/yarn/issues/2649) (above) is resolved._
|
118
117
|
|
data/PROJECTS.md
CHANGED
@@ -11,6 +11,13 @@ April 11, 2018: 2138
|
|
11
11
|
|
12
12
|
## Commercial Products Live
|
13
13
|
* **[Hawaii Chee](https://www.hawaiichee.com/)**, the signature product of [ShakaCode](http://www.shakacode.com), which is a vacation rental site focusing on Hawaii.
|
14
|
+
* **[RedFlagDeals](https://www.redflagdeals.com/)**, Canadian shopping site.
|
15
|
+
* **[YourMechanic](https://www.yourmechanic.com/)**, home calls for mechanics.
|
16
|
+
* **[Suntransfers](https://www.suntransfers.com/)**, airport car rides site.
|
17
|
+
* **[Decanter](http://www.decanter.com/)**, wine site.
|
18
|
+
* **[LocalWise](https://www.localwise.com/)**, local job site.
|
19
|
+
* **[Ellevest](https://www.ellevest.com/)**, investments for women.
|
20
|
+
* **[OppenheimerFunds](https://www.oppenheimerfunds.com/)**, investment site.
|
14
21
|
* **[KissKissBankBank](https://www.kisskissbankbank.com/)**, large French crowdfunding platform.
|
15
22
|
* **[HVMN](https://hvmn.com)**: Web ecommerce site for "biohacking" products.
|
16
23
|
* **[GuavaPass](https://guavapass.com/)**: Coaching client of [ShakaCode](http://www.shakacode.com) and React on Rails fan!
|
@@ -27,7 +34,6 @@ April 11, 2018: 2138
|
|
27
34
|
* **[Undeveloped](https://undeveloped.com/)**: Buy and sell domain names. ![image](https://cloud.githubusercontent.com/assets/1118459/19623703/7c6d63d0-9870-11e6-83f2-8b83ca49daa9.png)
|
28
35
|
* **[Foxford.ru](http://foxford.ru/)**: Online School ![2016-12-17_13-23-21](https://cloud.githubusercontent.com/assets/1118459/21290377/1adacdf2-c45c-11e6-97c1-f726ab749b2d.png)
|
29
36
|
* **[CareerBuilder for Employers](https://hiring.careerbuilder.com/)**: CareerBuilder's marketing/ecommerce website. We've integrated React on Rails and have deployed the application via Cloud 66, and are busy integrating this into other projects!
|
30
|
-
* **[Josephine](https://www.josephine.com)**: The private network for home cooked meals.
|
31
37
|
* **[first](https://first.io/)**: Data-driven Relational Marketing for Real Estate.
|
32
38
|
|
33
39
|
## Open Source Projects Live
|
data/README.md
CHANGED
@@ -357,10 +357,16 @@ You have 2 ways to specify your React components. You can either register the Re
|
|
357
357
|
|
358
358
|
ReactOnRails will automatically detect a registered generator function. Thus, there is no difference between registering a React Component versus a "generator function."
|
359
359
|
|
360
|
+
#### react_component_hash for Generator Functions
|
360
361
|
Another reason to use a generator 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`.
|
361
362
|
|
362
363
|
For server rendering, if you wish to return multiple HTML strings from a generator function, you may return an Object from your generator 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:
|
364
|
+
|
365
|
+
```js
|
363
366
|
{ renderedHtml: { componentHtml, customKey1, customKey2} }
|
367
|
+
```
|
368
|
+
|
369
|
+
For details on using react_component_hash with react-helmet, see the docs below for the helper API and [docs/additional-reading/react-helmet.md](../docs/additional-reading/react-helmet.md).
|
364
370
|
|
365
371
|
### Rails Context and Generator Functions
|
366
372
|
When you use a "generator function" to create react components (or renderedHtml on the server), or you used shared redux stores, you get two params passed to your function that creates a React component:
|
@@ -535,7 +541,44 @@ All options except `props, id, html_options` will inherit from your `react_on_ra
|
|
535
541
|
+ **replay_console:** Default is true. False will disable echoing server-rendering logs to the browser. While this can make troubleshooting server rendering difficult, so long as you have the configuration of `logging_on_server` set to true, you'll still see the errors on the server.
|
536
542
|
+ **logging_on_server:** Default is true. True will log JS console messages and errors to the server.
|
537
543
|
+ **raise_on_prerender_error:** Default is false. True will throw an error on the server side rendering. Your controller will have to handle the error.
|
544
|
+
|
545
|
+
### react_component_hash
|
546
|
+
`react_component_hash` is used to return multiple HTML strings for server rendering, such as for
|
547
|
+
adding meta-tags to a page. It is exactly like react_component except for the following:
|
548
|
+
|
549
|
+
1. `prerender: true` is automatically added to options, as this method doesn't make sense for
|
550
|
+
client only rendering.
|
551
|
+
2. Your JavaScript for server rendering must return an Object for the key `server_rendered_html`.
|
552
|
+
3. Your view code must expect an object and not a string.
|
553
|
+
|
554
|
+
Here is an example of ERB view code:
|
555
|
+
|
556
|
+
```erb
|
557
|
+
<% react_helmet_app = react_component_hash("ReactHelmetApp", prerender: true,
|
558
|
+
props: { helloWorldData: { name: "Mr. Server Side Rendering"}},
|
559
|
+
id: "react-helmet-0", trace: true) %>
|
560
|
+
<% content_for :title do %>
|
561
|
+
<%= react_helmet_app['title'] %>
|
562
|
+
<% end %>
|
563
|
+
<%= react_helmet_app["componentHtml"] %>
|
564
|
+
```
|
538
565
|
|
566
|
+
And here is the JavaScript code:
|
567
|
+
|
568
|
+
```js
|
569
|
+
export default (props, _railsContext) => {
|
570
|
+
const componentHtml = renderToString(<ReactHelmet {...props} />);
|
571
|
+
const helmet = Helmet.renderStatic();
|
572
|
+
|
573
|
+
const renderedHtml = {
|
574
|
+
componentHtml,
|
575
|
+
title: helmet.title.toString(),
|
576
|
+
};
|
577
|
+
return { renderedHtml };
|
578
|
+
};
|
579
|
+
|
580
|
+
```
|
581
|
+
|
539
582
|
### redux_store
|
540
583
|
#### Controller Extension
|
541
584
|
Include the module `ReactOnRails::Controller` in your controller, probably in ApplicationController. This will provide the following controller method, which you can call in your controller actions:
|
data/Rakefile
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
# Rake will automatically load any *.rake files inside of the "rakelib" folder
|
4
4
|
# See rakelib/
|
5
|
+
|
6
|
+
require_relative "./spec/react_on_rails/support/rails32_helper"
|
7
|
+
|
5
8
|
tasks = %w[run_rspec lint]
|
6
9
|
prepare_for_ci = %w[node_package dummy_apps]
|
7
10
|
|
@@ -11,7 +14,7 @@ if ENV["USE_COVERALLS"] == "TRUE"
|
|
11
14
|
tasks << "coveralls:push"
|
12
15
|
end
|
13
16
|
|
14
|
-
if
|
17
|
+
if using_rails32?
|
15
18
|
tasks = %w[run_rspec:gem_rails32 run_rspec:dummy_no_webpacker]
|
16
19
|
prepare_for_ci = %w[node_package dummy_apps:dummy_no_webpacker]
|
17
20
|
end
|
@@ -8,25 +8,25 @@ RSpec.configure do |config|
|
|
8
8
|
ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
|
9
9
|
```
|
10
10
|
|
11
|
-
You can pass one or more RSpec metatags as an optional second parameter to this helper method if you want this helper to run on examples other than where `:js
|
11
|
+
You can pass one or more RSpec metatags as an optional second parameter to this helper method if you want this helper to run on examples other than where `:js`, `:server_rendering`, or `:controller` (those are the defaults). The helper will compile webpack files at most once per test run. The helper will not compile the webpack files unless they are out of date (stale). The helper is configurable in terms of what command is used to prepare the files. If you don't specify these metatags for your relevant JavaScript tests, then you'll need to do the following.
|
12
12
|
|
13
13
|
If you are using Webpack to build CSS assets, you should do something like this to ensure that you assets are built for any specs under `specs/requests` or `specs/features`:
|
14
14
|
|
15
15
|
```ruby
|
16
16
|
ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config, :requires_webpack_assets)
|
17
|
-
|
18
|
-
# Because we're using some CSS Webpack files, we need to ensure the webpack files are generated
|
19
|
-
# for all feature specs. https://github.com/shakacode/react_on_rails/issues/792
|
20
17
|
config.define_derived_metadata(file_path: %r{spec/(features|requests)}) do |metadata|
|
21
18
|
metadata[:requires_webpack_assets] = true
|
22
19
|
end
|
23
20
|
```
|
24
21
|
|
25
22
|
Please take note of the following:
|
23
|
+
- If you are using Webpacker, be **SURE** to configure the `source_path` in your `config/webpacker.yml` unless you are using the defaults for webpacker. If you are not using webpacker, all files in the node_modules_location are used for your test sources.
|
24
|
+
|
26
25
|
- This utility uses your `build_test_command` to build the static generated files. This command **must not** include the `--watch` option. If you have different server and client bundle files, this command **must** create all the bundles. If you are using webpacker, the default value will come from the `config/webpacker.yml` value for the `public_output_path` and the `source_path`
|
26
|
+
|
27
27
|
- If you add an older file to your source files, that is already older than the produced output files, no new recompilation is done. The solution to this issue is to clear out your directory of webpack generated files when adding new source files that may have older dates. This is actually a common occurrence when you've built your test generated files and then you sync up your repository files.
|
28
28
|
|
29
|
-
- By default, the webpack processes look for the `
|
29
|
+
- By default, the webpack processes look for the `config.generated_assets_dir` folder for generated files, configured via setting `webpack_generated_files`, in the `config/react_on_rails.rb`. If the `config.generated_assets_dir` folder is missing, is empty, or contains files in the `config.webpack_generated_files` list with `mtime`s older than any of the files in your `client` folder, the helper will recompile your assets. You can override the location of these files inside of `config/initializers/react_on_rails.rb` by passing a filepath (relative to the root of the app) to the `generated_assets_dir` configuration option.
|
30
30
|
|
31
31
|
The following `config/react_on_rails.rb` settings **must** match your setup:
|
32
32
|
```ruby
|
@@ -47,7 +47,8 @@ ReactOnRails.configure do |config|
|
|
47
47
|
# Alternately, you may configure this. It is relative to your Rails root directory.
|
48
48
|
# A custom, non-webpacker, config might use something like:
|
49
49
|
#
|
50
|
-
config.generated_assets_dir = File.join(%w[public webpack], Rails.env)
|
50
|
+
# config.generated_assets_dir = File.join(%w[public webpack], Rails.env)
|
51
|
+
# This setting should not be used if using webpacker.
|
51
52
|
|
52
53
|
# The test helper needs to know where your JavaScript files exist. The default is configured
|
53
54
|
# by your config/webpacker.yml soure_path:
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# NOTE: ReactOnRails::Utils.using_webpacker? always will return false when called here.
|
4
|
-
|
5
3
|
module ReactOnRails
|
6
4
|
def self.configure
|
7
5
|
yield(configuration)
|
@@ -21,6 +19,29 @@ module ReactOnRails
|
|
21
19
|
check_i18n_directory_exists
|
22
20
|
check_i18n_yml_directory_exists
|
23
21
|
check_server_render_method_is_only_execjs
|
22
|
+
error_if_using_webpacker_and_generated_assets_dir_not_match_public_output_path
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.error_if_using_webpacker_and_generated_assets_dir_not_match_public_output_path
|
26
|
+
return unless ReactOnRails::WebpackerUtils.using_webpacker?
|
27
|
+
|
28
|
+
return if @configuration.generated_assets_dir.blank?
|
29
|
+
|
30
|
+
webpacker_public_output_path = ReactOnRails::WebpackerUtils.webpacker_public_output_path
|
31
|
+
|
32
|
+
if File.expand_path(@configuration.generated_assets_dir) == webpacker_public_output_path.to_s
|
33
|
+
Rails.logger.warn("You specified /config/initializers/react_on_rails.rb generated_assets_dir "\
|
34
|
+
"with Webpacker. Remove this line from your configuration file.")
|
35
|
+
else
|
36
|
+
msg = <<-MSG.strip_heredoc
|
37
|
+
Error configuring /config/initializers/react_on_rails.rb: You are using webpacker
|
38
|
+
and your specified value for generated_assets_dir = #{@configuration.generated_assets_dir}
|
39
|
+
that does not match the value for public_output_path specified in
|
40
|
+
webpacker.yml = #{webpacker_public_output_path}. You should remove the configuration
|
41
|
+
value for "generated_assets_dir" from your config/initializers/react_on_rails.rb file.
|
42
|
+
MSG
|
43
|
+
raise ReactOnRails::Error, msg
|
44
|
+
end
|
24
45
|
end
|
25
46
|
|
26
47
|
def self.check_server_render_method_is_only_execjs
|
@@ -28,7 +49,7 @@ module ReactOnRails
|
|
28
49
|
@configuration.server_render_method == "ExecJS"
|
29
50
|
|
30
51
|
msg = <<-MSG.strip_heredoc
|
31
|
-
Error configuring /config/react_on_rails.rb: invalid value for `config.server_render_method`.
|
52
|
+
Error configuring /config/initializers/react_on_rails.rb: invalid value for `config.server_render_method`.
|
32
53
|
If you wish to use a server render method other than ExecJS, contact justin@shakacode.com
|
33
54
|
for details.
|
34
55
|
MSG
|
@@ -40,7 +61,7 @@ module ReactOnRails
|
|
40
61
|
return if Dir.exist?(@configuration.i18n_dir)
|
41
62
|
|
42
63
|
msg = <<-MSG.strip_heredoc
|
43
|
-
Error configuring /config/react_on_rails.rb: invalid value for `config.i18n_dir`.
|
64
|
+
Error configuring /config/initializers/react_on_rails.rb: invalid value for `config.i18n_dir`.
|
44
65
|
Directory does not exist: #{@configuration.i18n_dir}. Set to value to nil or comment it
|
45
66
|
out if not using the React on Rails i18n feature.
|
46
67
|
MSG
|
@@ -52,7 +73,7 @@ module ReactOnRails
|
|
52
73
|
return if Dir.exist?(@configuration.i18n_yml_dir)
|
53
74
|
|
54
75
|
msg = <<-MSG.strip_heredoc
|
55
|
-
Error configuring /config/react_on_rails.rb: invalid value for `config.i18n_yml_dir`.
|
76
|
+
Error configuring /config/initializers/react_on_rails.rb: invalid value for `config.i18n_yml_dir`.
|
56
77
|
Directory does not exist: #{@configuration.i18n_yml_dir}. Set to value to nil or comment it
|
57
78
|
out if not using this i18n with React on Rails, or if you want to use all translation files.
|
58
79
|
MSG
|
@@ -60,22 +81,31 @@ module ReactOnRails
|
|
60
81
|
end
|
61
82
|
|
62
83
|
def self.ensure_generated_assets_dir_present
|
63
|
-
return if @configuration.generated_assets_dir.present?
|
84
|
+
return if @configuration.generated_assets_dir.present? || ReactOnRails::WebpackerUtils.using_webpacker?
|
64
85
|
|
65
86
|
@configuration.generated_assets_dir = DEFAULT_GENERATED_ASSETS_DIR
|
66
|
-
|
87
|
+
Rails.logger.warn "ReactOnRails: Set generated_assets_dir to default: #{DEFAULT_GENERATED_ASSETS_DIR}"
|
67
88
|
end
|
68
89
|
|
69
90
|
def self.configure_generated_assets_dirs_deprecation
|
70
91
|
return if @configuration.generated_assets_dirs.blank?
|
71
92
|
|
72
|
-
|
93
|
+
if ReactOnRails::WebpackerUtils.using_webpacker?
|
94
|
+
webpacker_public_output_path = ReactOnRails::WebpackerUtils.webpacker_public_output_path
|
95
|
+
Rails.logger.warn "Error configuring config/initializers/react_on_rails. Define neither the "\
|
96
|
+
"generated_assets_dirs no the generated_assets_dir when using Webpacker. This is defined by "\
|
97
|
+
"public_output_path specified in webpacker.yml = #{webpacker_public_output_path}."
|
98
|
+
return
|
99
|
+
end
|
100
|
+
|
101
|
+
Rails.logger.warn "[DEPRECATION] ReactOnRails: Use config.generated_assets_dir rather than "\
|
73
102
|
"generated_assets_dirs"
|
74
103
|
if @configuration.generated_assets_dir.blank?
|
75
104
|
@configuration.generated_assets_dir = @configuration.generated_assets_dirs
|
76
105
|
else
|
77
|
-
|
78
|
-
"generated_assets_dir defined. Define ONLY generated_assets_dir"
|
106
|
+
Rails.logger.warn "[DEPRECATION] ReactOnRails. You have both generated_assets_dirs and "\
|
107
|
+
"generated_assets_dir defined. Define ONLY generated_assets_dir if NOT using Webpacker"\
|
108
|
+
" and define neither if using Webpacker"
|
79
109
|
end
|
80
110
|
end
|
81
111
|
|
@@ -91,14 +121,18 @@ module ReactOnRails
|
|
91
121
|
def self.ensure_server_bundle_js_file_has_no_path
|
92
122
|
return unless @configuration.server_bundle_js_file.include?(File::SEPARATOR)
|
93
123
|
|
94
|
-
|
95
|
-
"All generated files must go in #{@configuration.generated_assets_dir}"
|
124
|
+
assets_dir = ReactOnRails::Utils.generated_assets_full_path
|
96
125
|
@configuration.server_bundle_js_file = File.basename(@configuration.server_bundle_js_file)
|
126
|
+
|
127
|
+
Rails.logger_warn do
|
128
|
+
"[DEPRECATION] ReactOnRails: remove path from server_bundle_js_file in configuration. "\
|
129
|
+
"All generated files must go in #{assets_dir}. Using file basename #{@configuration.server_bundle_js_file}"
|
130
|
+
end
|
97
131
|
end
|
98
132
|
|
99
133
|
def self.configure_skip_display_none_deprecation
|
100
134
|
return if @configuration.skip_display_none.nil?
|
101
|
-
|
135
|
+
Rails.logger.warn "[DEPRECATION] ReactOnRails: remove skip_display_none from configuration."
|
102
136
|
end
|
103
137
|
|
104
138
|
def self.configuration
|
@@ -120,17 +120,35 @@ module ReactOnRails
|
|
120
120
|
|
121
121
|
else
|
122
122
|
msg = <<-MSG.strip_heredoc
|
123
|
-
ReactOnRails: server_rendered_html is expected to be a String. If you're
|
124
|
-
use a generator function to return a Hash to your ruby view code, then use
|
123
|
+
ReactOnRails: server_rendered_html is expected to be a String for #{component_name}. If you're
|
124
|
+
trying to use a generator function to return a Hash to your ruby view code, then use
|
125
125
|
react_component_hash instead of react_component and see
|
126
126
|
https://github.com/shakacode/react_on_rails/blob/master/spec/dummy/client/app/startup/ReactHelmetServerApp.jsx
|
127
|
-
for an example of the
|
127
|
+
for an example of the JavaScript code."
|
128
128
|
MSG
|
129
129
|
raise ReactOnRails::Error, msg
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
|
+
# react_component_hash is used to return multiple HTML strings for server rendering, such as for
|
134
|
+
# adding meta-tags to a page.
|
135
|
+
# It is exactly like react_component except for the following:
|
136
|
+
# 1. prerender: true is automatically added, as this method doesn't make sense for client only
|
137
|
+
# rendering.
|
138
|
+
# 2. Your JavaScript for server rendering must return an Object for the key server_rendered_html.
|
139
|
+
# 3. Your view code must expect an object and not a string.
|
140
|
+
#
|
141
|
+
# Here is an example of the view code:
|
142
|
+
# <% react_helmet_app = react_component_hash("ReactHelmetApp", prerender: true,
|
143
|
+
# props: { helloWorldData: { name: "Mr. Server Side Rendering"}},
|
144
|
+
# id: "react-helmet-0", trace: true) %>
|
145
|
+
# <% content_for :title do %>
|
146
|
+
# <%= react_helmet_app['title'] %>
|
147
|
+
# <% end %>
|
148
|
+
# <%= react_helmet_app["componentHtml"] %>
|
149
|
+
#
|
133
150
|
def react_component_hash(component_name, options = {})
|
151
|
+
options[:prerender] = true
|
134
152
|
internal_result = internal_react_component(component_name, options)
|
135
153
|
server_rendered_html = internal_result[:result]["html"]
|
136
154
|
console_script = internal_result[:result]["consoleReplayScript"]
|
@@ -148,9 +166,9 @@ module ReactOnRails
|
|
148
166
|
)
|
149
167
|
else
|
150
168
|
msg = <<-MSG.strip_heredoc
|
151
|
-
|
152
|
-
|
153
|
-
|
169
|
+
Generator function used by react_component_hash for #{component_name} is expected to return
|
170
|
+
an Object. See https://github.com/shakacode/react_on_rails/blob/master/spec/dummy/client/app/startup/ReactHelmetServerApp.jsx
|
171
|
+
for an example of the JavaScript code."
|
154
172
|
MSG
|
155
173
|
raise ReactOnRails::Error, msg
|
156
174
|
end
|
@@ -485,7 +503,9 @@ module ReactOnRails
|
|
485
503
|
inMailer: in_mailer?,
|
486
504
|
# Locale settings
|
487
505
|
i18nLocale: I18n.locale,
|
488
|
-
i18nDefaultLocale: I18n.default_locale
|
506
|
+
i18nDefaultLocale: I18n.default_locale,
|
507
|
+
rorVersion: ReactOnRails::VERSION,
|
508
|
+
rorPro: ReactOnRails::Utils.react_on_rails_pro?
|
489
509
|
}
|
490
510
|
if defined?(request) && request.present?
|
491
511
|
# Check for encoding of the request's original_url and try to force-encoding the
|
@@ -9,12 +9,8 @@ require_relative "server_rendering_pool/ruby_embedded_java_script"
|
|
9
9
|
module ReactOnRails
|
10
10
|
module ServerRenderingPool
|
11
11
|
class << self
|
12
|
-
def react_on_rails_pro?
|
13
|
-
@react_on_rails_pro ||= gem_available?("react_on_rails_pro")
|
14
|
-
end
|
15
|
-
|
16
12
|
def pool
|
17
|
-
@pool ||= if react_on_rails_pro?
|
13
|
+
@pool ||= if ReactOnRails::Utils.react_on_rails_pro?
|
18
14
|
ReactOnRailsPro::ServerRenderingPool::ProRendering
|
19
15
|
else
|
20
16
|
ReactOnRails::ServerRenderingPool::RubyEmbeddedJavaScript
|
@@ -26,16 +22,6 @@ module ReactOnRails
|
|
26
22
|
def server_render_js_with_console_logging(js_code, render_options)
|
27
23
|
pool.exec_server_render_js(js_code, render_options)
|
28
24
|
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def gem_available?(name)
|
33
|
-
Gem::Specification.find_by_name(name)
|
34
|
-
rescue Gem::LoadError
|
35
|
-
false
|
36
|
-
rescue StandardError
|
37
|
-
Gem.available?(name)
|
38
|
-
end
|
39
25
|
end
|
40
26
|
end
|
41
27
|
end
|
@@ -31,7 +31,7 @@ module ReactOnRails
|
|
31
31
|
# Params:
|
32
32
|
# config - config for rspec
|
33
33
|
# metatags - metatags to add the ensure_assets_compiled check.
|
34
|
-
# Default is :js, :server_rendering
|
34
|
+
# Default is :js, :server_rendering, :controller
|
35
35
|
def self.configure_rspec_to_compile_assets(config, *metatags)
|
36
36
|
metatags = %i[js server_rendering controller] if metatags.empty?
|
37
37
|
|
@@ -48,30 +48,31 @@ module ReactOnRails
|
|
48
48
|
# defaults to ReactOnRails::TestHelper::WebpackAssetsStatusChecker
|
49
49
|
# webpack_assets_compiler: provide one method: `def compile`
|
50
50
|
# defaults to ReactOnRails::TestHelper::WebpackAssetsCompiler
|
51
|
-
# source_path and
|
51
|
+
# source_path and generated_assets_full_path are passed into the default webpack_assets_status_checker if you
|
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
55
|
def self.ensure_assets_compiled(webpack_assets_status_checker: nil,
|
56
56
|
webpack_assets_compiler: nil,
|
57
57
|
source_path: nil,
|
58
|
-
|
58
|
+
generated_assets_full_path: nil,
|
59
59
|
webpack_generated_files: nil)
|
60
60
|
ReactOnRails::WebpackerUtils.check_manifest_not_cached
|
61
61
|
if webpack_assets_status_checker.nil?
|
62
62
|
source_path ||= ReactOnRails::Utils.source_path
|
63
|
-
|
63
|
+
generated_assets_full_path ||= ReactOnRails::Utils.generated_assets_full_path
|
64
64
|
webpack_generated_files ||= ReactOnRails.configuration.webpack_generated_files
|
65
65
|
|
66
66
|
webpack_assets_status_checker ||=
|
67
67
|
WebpackAssetsStatusChecker.new(source_path: source_path,
|
68
|
-
|
68
|
+
generated_assets_full_path: generated_assets_full_path,
|
69
69
|
webpack_generated_files: webpack_generated_files)
|
70
70
|
|
71
71
|
unless @printed_once
|
72
72
|
puts
|
73
|
-
puts "====> React On Rails: Checking
|
74
|
-
|
73
|
+
puts "====> React On Rails: Checking files in "\
|
74
|
+
"#{webpack_assets_status_checker.generated_assets_full_path} for "\
|
75
|
+
"outdated/missing bundles based on source_path #{source_path}"
|
75
76
|
puts
|
76
77
|
@printed_once = true
|
77
78
|
end
|
@@ -13,14 +13,14 @@ module ReactOnRails
|
|
13
13
|
# source_path is typically configured in the webpacker.yml file
|
14
14
|
# for `source_path`
|
15
15
|
# or for legacy React on Rails, it's /client, where all client files go
|
16
|
-
attr_reader :source_path, :
|
16
|
+
attr_reader :source_path, :generated_assets_full_path
|
17
17
|
|
18
18
|
def initialize(
|
19
|
-
|
19
|
+
generated_assets_full_path: required("generated_assets_full_path"),
|
20
20
|
source_path: required("source_path"),
|
21
21
|
webpack_generated_files: required("webpack_generated_files")
|
22
22
|
)
|
23
|
-
@
|
23
|
+
@generated_assets_full_path = generated_assets_full_path
|
24
24
|
@source_path = source_path
|
25
25
|
@webpack_generated_files = webpack_generated_files
|
26
26
|
end
|
@@ -59,13 +59,13 @@ module ReactOnRails
|
|
59
59
|
if webpack_generated_files.present?
|
60
60
|
webpack_generated_files
|
61
61
|
else
|
62
|
-
file_list = make_file_list(make_globs(
|
62
|
+
file_list = make_file_list(make_globs(generated_assets_full_path)).to_ary
|
63
63
|
puts "V" * 80
|
64
64
|
puts "Please define config.webpack_generated_files (array) so the test helper knows "\
|
65
65
|
"which files are required. If you are using webpacker, you typically need to only "\
|
66
66
|
"include 'manifest.json'."
|
67
67
|
puts "Detected the possible following files to check for webpack compilation in "\
|
68
|
-
"#{
|
68
|
+
"#{generated_assets_full_path}"
|
69
69
|
puts file_list.join("\n")
|
70
70
|
puts "^" * 80
|
71
71
|
file_list
|
data/lib/react_on_rails/utils.rb
CHANGED
@@ -76,8 +76,8 @@ exitstatus: #{status.exitstatus}#{stdout_msg}#{stderr_msg}
|
|
76
76
|
begin
|
77
77
|
bundle_js_file_path(bundle_name)
|
78
78
|
rescue Webpacker::Manifest::MissingEntryError
|
79
|
-
|
80
|
-
|
79
|
+
File.join(ReactOnRails::WebpackerUtils.webpacker_public_output_path,
|
80
|
+
bundle_name)
|
81
81
|
end
|
82
82
|
else
|
83
83
|
bundle_js_file_path(bundle_name)
|
@@ -90,7 +90,8 @@ exitstatus: #{status.exitstatus}#{stdout_msg}#{stderr_msg}
|
|
90
90
|
else
|
91
91
|
# Default to the non-hashed name in the specified output directory, which, for legacy
|
92
92
|
# React on Rails, this is the output directory picked up by the asset pipeline.
|
93
|
-
|
93
|
+
# For Webpacker, this is the public output path defined in the webpacker.yml file.
|
94
|
+
File.join(generated_assets_full_path, bundle_name)
|
94
95
|
end
|
95
96
|
end
|
96
97
|
|
@@ -130,12 +131,24 @@ exitstatus: #{status.exitstatus}#{stdout_msg}#{stderr_msg}
|
|
130
131
|
end
|
131
132
|
end
|
132
133
|
|
133
|
-
def self.
|
134
|
+
def self.generated_assets_full_path
|
134
135
|
if ReactOnRails::WebpackerUtils.using_webpacker?
|
135
136
|
ReactOnRails::WebpackerUtils.webpacker_public_output_path
|
136
137
|
else
|
137
|
-
ReactOnRails.configuration.generated_assets_dir
|
138
|
+
File.expand_path(ReactOnRails.configuration.generated_assets_dir)
|
138
139
|
end
|
139
140
|
end
|
141
|
+
|
142
|
+
def self.gem_available?(name)
|
143
|
+
Gem::Specification.find_by_name(name).present?
|
144
|
+
rescue Gem::LoadError
|
145
|
+
false
|
146
|
+
rescue StandardError
|
147
|
+
Gem.available?(name).present?
|
148
|
+
end
|
149
|
+
|
150
|
+
def self.react_on_rails_pro?
|
151
|
+
@react_on_rails_pro ||= gem_available?("react_on_rails_pro")
|
152
|
+
end
|
140
153
|
end
|
141
154
|
end
|
@@ -1,18 +1,20 @@
|
|
1
1
|
module ReactOnRails
|
2
2
|
module WebpackerUtils
|
3
3
|
def self.using_webpacker?
|
4
|
-
|
4
|
+
ReactOnRails::Utils.gem_available?("webpacker")
|
5
5
|
end
|
6
6
|
|
7
7
|
def self.bundle_js_file_path_from_webpacker(bundle_name)
|
8
|
-
|
9
|
-
|
8
|
+
# Note Webpacker 3.4.3 manifest lookup is inside of the public_output_path
|
9
|
+
# [2] (pry) ReactOnRails::WebpackerUtils: 0> Webpacker.manifest.lookup("app-bundle.js")
|
10
|
+
# "/webpack/development/app-bundle-c1d2b6ab73dffa7d9c0e.js"
|
11
|
+
hashed_bundle_name = Webpacker.manifest.lookup!(bundle_name)
|
12
|
+
|
10
13
|
if Webpacker.dev_server.running?
|
11
|
-
|
12
|
-
result
|
14
|
+
"#{Webpacker.dev_server.protocol}://#{Webpacker.dev_server.host_with_port}#{hashed_bundle_name}"
|
13
15
|
else
|
14
16
|
# Next line will throw if the file or manifest does not exist
|
15
|
-
|
17
|
+
File.expand_path(File.join("public", hashed_bundle_name)).to_s
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
@@ -21,7 +23,8 @@ module ReactOnRails
|
|
21
23
|
end
|
22
24
|
|
23
25
|
def self.webpacker_public_output_path
|
24
|
-
Webpacker
|
26
|
+
# Webpacker has the full absolute path of webpacker output files in a pathname
|
27
|
+
Webpacker.config.public_output_path.to_s
|
25
28
|
end
|
26
29
|
|
27
30
|
def self.manifest_exists?
|
data/package.json
CHANGED
data/react_on_rails.gemspec
CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
s.add_dependency "connection_pool"
|
30
30
|
s.add_dependency "execjs", "~> 2.5"
|
31
31
|
s.add_dependency "rails", ">= 3.2"
|
32
|
-
s.add_dependency "rainbow", "~>
|
32
|
+
s.add_dependency "rainbow", "~> 3.0"
|
33
33
|
|
34
34
|
s.add_development_dependency "awesome_print"
|
35
35
|
s.add_development_dependency "bundler", "~> 1"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: react_on_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 11.0.
|
4
|
+
version: 11.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Gordon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04
|
11
|
+
date: 2018-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '3.0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '3.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: awesome_print
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|