react_on_rails 13.0.0.beta.0 → 13.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -2
- data/NEWS.md +1 -1
- data/README.md +4 -4
- data/docs/additional-details/recommended-project-structure.md +1 -1
- data/docs/guides/rails-webpacker-react-integration-options.md +4 -3
- data/docs/guides/react-server-rendering.md +1 -1
- data/docs/guides/tutorial.md +6 -5
- data/docs/guides/webpack-configuration.md +1 -1
- data/docs/home.md +1 -1
- data/lib/generators/react_on_rails/base_generator.rb +1 -0
- data/lib/generators/react_on_rails/templates/base/base/babel.config.js.tt +1 -1
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/clientWebpackConfig.js.tt +1 -1
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt +1 -1
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/development.js.tt +1 -3
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/production.js.tt +1 -3
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/serverWebpackConfig.js.tt +1 -1
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/test.js.tt +9 -0
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/webpack.config.js.tt +2 -2
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/webpackConfig.js.tt +1 -1
- data/lib/react_on_rails/helper.rb +18 -16
- data/lib/react_on_rails/json_parse_error.rb +1 -1
- data/lib/react_on_rails/prerender_error.rb +5 -2
- data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +19 -4
- data/lib/react_on_rails/version.rb +1 -1
- data/package.json +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70b55160147309cf5da5f36f8d1f23ebad08c70b5d13362acc38ed1c6fbcd780
|
4
|
+
data.tar.gz: d6635ba54093daec5ee69412f46b0751d18dd035e37c69886625e94f3bc24728
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bffe017f74585f13ddb5a647d0684b778e48fc40ebf62e586d0b1091cfa04716602a1fa54c21118fc0b43e2d4d9b6d65b9a5c333c3ea6b31ad2a90b9e7675a60
|
7
|
+
data.tar.gz: 2ea465e9a7cc0da248743bade989b811f1703371ca8dd757e9b072cb6b30106e4ebf2cc9351f742d4b8c63782b0b101183ca676733418df0d12677a84f05ccec
|
data/CHANGELOG.md
CHANGED
@@ -16,6 +16,21 @@ Please follow the recommendations outlined at [keepachangelog.com](http://keepac
|
|
16
16
|
Changes since last non-beta release.
|
17
17
|
|
18
18
|
*Please add entries here for your pull requests that are not yet released.*
|
19
|
+
### [13.0.2] - 2022-03-09
|
20
|
+
#### Fixed
|
21
|
+
- React 16 doesn't support version property, causing problems loading React on Rails. [PR 1435](https://github.com/shakacode/react_on_rails/pull/1435) by [justin808](https://github.com/justin808).
|
22
|
+
|
23
|
+
### [13.0.1] - 2022-02-09
|
24
|
+
#### Improved
|
25
|
+
- Updated the default generator. [PR 1431](https://github.com/shakacode/react_on_rails/pull/1431) by [justin808](https://github.com/justin808).
|
26
|
+
|
27
|
+
### [13.0.0] - 2022-02-08
|
28
|
+
#### Breaking
|
29
|
+
- Removed webpacker as a dependency. Add gem Shakapacker to your project, and update your package.json to also use shakapacker.
|
30
|
+
|
31
|
+
#### Fixed
|
32
|
+
- Propper throwing of exceptions.
|
33
|
+
- Default configuration better handles test env.
|
19
34
|
|
20
35
|
### [12.6.0] - 2022-01-22
|
21
36
|
|
@@ -39,7 +54,7 @@ Changes since last non-beta release.
|
|
39
54
|
- Supports Rails 7.
|
40
55
|
|
41
56
|
#### Changed
|
42
|
-
- Changed logic of determining the usage of the default rails/webpacker webpack config or a custom command to only check if the config.build_production_command is defined. [PR 1402](https://github.com/shakacode/react_on_rails/pull/1402)by [justin808](https://github.com/justin808) and [gscarv13](https://github.com/gscarv13).
|
57
|
+
- Changed logic of determining the usage of the default rails/webpacker webpack config or a custom command to only check if the config.build_production_command is defined. [PR 1402](https://github.com/shakacode/react_on_rails/pull/1402) by [justin808](https://github.com/justin808) and [gscarv13](https://github.com/gscarv13).
|
43
58
|
- Minimimum required Ruby is 2.7 to match lastest rails/webpacker.
|
44
59
|
|
45
60
|
### [12.4.0] - 2021-09-22
|
@@ -999,7 +1014,9 @@ Best done with Object destructing:
|
|
999
1014
|
##### Fixed
|
1000
1015
|
- Fix several generator related issues.
|
1001
1016
|
|
1002
|
-
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/
|
1017
|
+
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/13.0.1...master
|
1018
|
+
[13.0.1]: https://github.com/shakacode/react_on_rails/compare/13.0.0...13.0.1
|
1019
|
+
[13.0.0]: https://github.com/shakacode/react_on_rails/compare/12.6.0...13.0.0
|
1003
1020
|
[12.6.0]: https://github.com/shakacode/react_on_rails/compare/12.5.2...12.6.0
|
1004
1021
|
[12.5.2]: https://github.com/shakacode/react_on_rails/compare/12.5.1...12.5.2
|
1005
1022
|
[12.5.1]: https://github.com/shakacode/react_on_rails/compare/12.5.0...12.5.1
|
data/NEWS.md
CHANGED
@@ -7,7 +7,7 @@ RR 474: React on Rails V12 – Don’t Shave That Yak! with Justin Gordon](https
|
|
7
7
|
|
8
8
|
* **October 1, 2020**: See the [spec/dummy](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy) example repo for a simple configuration of webpack via the rails/webpacker gem
|
9
9
|
that supports SSR.
|
10
|
-
* **August 2, 2020**: See the example repo of [React on Rails Tutorial With SSR, HMR fast refresh, and TypeScript](https://github.com/shakacode/
|
10
|
+
* **August 2, 2020**: See the example repo of [React on Rails Tutorial With SSR, HMR fast refresh, and TypeScript](https://github.com/shakacode/react_on_rails_demo_ssr_hmr) for a new way to setup the creation of your SSR bundle with `rails/webpacker`.
|
11
11
|
* July 8, 2020: Release **v12**.
|
12
12
|
1. **React Hooks Support** for top level components
|
13
13
|
2. **Typescript bindings**
|
data/README.md
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
|
14
14
|
# News
|
15
15
|
* ShakaCode now maintains the official successor to `rails/webpacker`, [`shakapacker`](https://github.com/shakacode/shakapacker).
|
16
|
-
* Project is updated to support Rails 7
|
16
|
+
* Project is updated to support Rails 7 and Shakapacker v6+!
|
17
17
|
|
18
18
|
-----
|
19
19
|
|
@@ -44,12 +44,12 @@ To provide a high performance framework for integrating Ruby on Rails with React
|
|
44
44
|
Given that `rails/webpacker` gem already provides basic React integration, why would you use "React on Rails"?
|
45
45
|
|
46
46
|
1. Easy passing of props directly from your Rails view to your React components rather than having your Rails view load and then make a separate request to your API.
|
47
|
-
1. Tight integration with [rails/webpacker](https://github.com/rails/webpacker).
|
48
|
-
1. Server-Side Rendering (SSR), often used for SEO crawler indexing and UX performance
|
47
|
+
1. Tight integration with [shakapacker](https://github.com/shakacode/shakapacker) (or it's predecessor [rails/webpacker](https://github.com/rails/webpacker)).
|
48
|
+
1. Server-Side Rendering (SSR), often used for SEO crawler indexing and UX performance.
|
49
49
|
1. [Redux](https://github.com/reactjs/redux) and [React Router](https://github.com/ReactTraining/react-router#readme) integration with server-side-rendering.
|
50
50
|
1. [Internationalization (I18n) and (localization)](https://www.shakacode.com/react-on-rails/docs/guides/i18n)
|
51
51
|
1. A supportive community. This [web search shows how live public sites are using React on Rails](https://publicwww.com/websites/%22react-on-rails%22++-undeveloped.com+depth%3Aall/).
|
52
|
-
1. [
|
52
|
+
1. [ReScript Support](https://github.com/shakacode/rescript-react-on-rails-example).
|
53
53
|
|
54
54
|
See [Rails/Webpacker React Integration Options](https://www.shakacode.com/react-on-rails/docs/guides/rails-webpacker-react-integration-options) for comparisons to other gems.
|
55
55
|
|
@@ -12,7 +12,7 @@ app/javascript:
|
|
12
12
|
│ └── hello-world-bundle.js
|
13
13
|
```
|
14
14
|
|
15
|
-
Per the example repo [shakacode/
|
15
|
+
Per the example repo [shakacode/react_on_rails_demo_ssr_hmr](https://github.com/shakacode/react_on_rails_demo_ssr_hmr),
|
16
16
|
you should consider keeping your codebase mostly consistent with the defaults for [rails/webpacker](https://github.com/rails/webpacker).
|
17
17
|
|
18
18
|
## Steps to convert from the generator defaults to use a `/client` directory for source code
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Rails/Webpacker React Integration Options
|
1
|
+
# Shakapacker (Rails/Webpacker) React Integration Options
|
2
2
|
|
3
3
|
You only _need_ props hydration if you need SSR. However, there's no good reason to
|
4
4
|
have your app make a second round trip to the Rails server to get initialization props.
|
@@ -81,7 +81,7 @@ Webpack's HMR allows the replacement of modules for React in-place without reloa
|
|
81
81
|
### React Refresh Webpack Plugin
|
82
82
|
[github.com/pmmmwh/react-refresh-webpack-plugin](https://github.com/pmmmwh/react-refresh-webpack-plugin)
|
83
83
|
|
84
|
-
You can see an example commit of adding this [here](https://github.com/shakacode/
|
84
|
+
You can see an example commit of adding this [here](https://github.com/shakacode/react_on_rails_demo_ssr_hmr/commit/7e53803fce7034f5ecff335db1f400a5743a87e7).
|
85
85
|
|
86
86
|
1. Add react refresh packages:
|
87
87
|
`yarn add @pmmmwh/react-refresh-webpack-plugin react-refresh -D`
|
@@ -111,6 +111,8 @@ You can see an example commit of adding this [here](https://github.com/shakacode
|
|
111
111
|
}
|
112
112
|
```
|
113
113
|
|
114
|
+
---
|
115
|
+
|
114
116
|
### React Hot Loader (Deprecated)
|
115
117
|
|
116
118
|
1. Add the `react-hot-loader` and ` @hot-loader/react-dom` npm packages.
|
@@ -179,4 +181,3 @@ module.exports = environment.toWebpackConfig()
|
|
179
181
|
|
180
182
|
module.exports = environment;
|
181
183
|
```
|
182
|
-
|
@@ -3,7 +3,7 @@
|
|
3
3
|
See also [Client vs. Server Rendering](https://www.shakacode.com/react-on-rails/docs/guides/client-vs-server-rendering/).
|
4
4
|
|
5
5
|
## What is the easiest way to setup a webpack configuration for server-side-rendering?
|
6
|
-
See the example webpack setup here: [github.com/shakacode/
|
6
|
+
See the example webpack setup here: [github.com/shakacode/react_on_rails_demo_ssr_hmr](https://github.com/shakacode/react_on_rails_demo_ssr_hmr).
|
7
7
|
|
8
8
|
## What is Server Rendering?
|
9
9
|
|
data/docs/guides/tutorial.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# React on Rails Basic Tutorial
|
2
2
|
|
3
|
-
|
3
|
+
_Also see the example repo of [React on Rails Tutorial With SSR, HMR fast refresh, and TypeScript](https://github.com/shakacode/react_on_rails_demo_ssr_hmr)_
|
4
4
|
|
5
5
|
-----
|
6
6
|
|
7
|
-
*Updated for Ruby 2.7
|
7
|
+
*Updated for Ruby 2.7, Rails 7, React on Rails v13, and Shakapacker v6*
|
8
8
|
|
9
9
|
This tutorial guides you through setting up a new or existing Rails app with **React on Rails**, demonstrating Rails + React + Redux + Server Rendering.
|
10
10
|
|
@@ -23,7 +23,7 @@ By the time you read this, the latest may have changed. Be sure to check the ver
|
|
23
23
|
|
24
24
|
## Setting up your environment
|
25
25
|
|
26
|
-
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 14+. I recommend `rvm` or `
|
26
|
+
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 14+. I recommend `rvm` or `rbenv` and `nvm` to install Ruby and Node. Rails can be installed as an ordinary gem.
|
27
27
|
|
28
28
|
```
|
29
29
|
nvm install node # download and install latest stable Node
|
@@ -49,6 +49,7 @@ cd <directory where you want to create your new Rails app>
|
|
49
49
|
|
50
50
|
# Any name you like for the rails app
|
51
51
|
# Skip javascript so will add that next and get the current version
|
52
|
+
# This is for Rails 7
|
52
53
|
rails new --skip-turbolinks --skip-javascript test-react-on-rails
|
53
54
|
|
54
55
|
cd test-react-on-rails
|
@@ -60,7 +61,7 @@ of both the gem and npm package. In other words, don't use the `^` or `~` in the
|
|
60
61
|
_Use the latest version for `react_on_rails` and `shakapacker`._
|
61
62
|
|
62
63
|
```
|
63
|
-
gem 'react_on_rails', '13.0.
|
64
|
+
gem 'react_on_rails', '13.0.1' # prefer exact gem version to match npm version
|
64
65
|
gem 'shakapacker', '6.1.1' # prefer exact gem version to match npm version
|
65
66
|
|
66
67
|
```
|
@@ -68,7 +69,7 @@ gem 'shakapacker', '6.1.1' # prefer exact gem version to match npm v
|
|
68
69
|
Note: The latest released React On Rails version is considered stable. Please use the latest
|
69
70
|
version to ensure you get all the security patches and the best support.
|
70
71
|
|
71
|
-
## Run the
|
72
|
+
## Run the shakapacker (webpacker) generator
|
72
73
|
|
73
74
|
```terminal
|
74
75
|
bundle exec rails webpacker:install
|
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
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
13
|
|
14
|
-
Per the example repo [shakacode/
|
14
|
+
Per the example repo [shakacode/react_on_rails_demo_ssr_hmr](https://github.com/shakacode/react_on_rails_demo_ssr_hmr),
|
15
15
|
you should consider keeping your codebase mostly consistent with the defaults for [rails/webpacker](https://github.com/rails/webpacker).
|
16
16
|
|
17
17
|
# React on Rails
|
data/docs/home.md
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
## Example Apps
|
17
17
|
1. [spec/dummy](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy) example repo for a simple configuration of webpack via the rails/webpacker gem
|
18
18
|
that supports SSR.
|
19
|
-
2. Example repo of [React on Rails Tutorial With SSR, HMR fast refresh, and TypeScript](https://github.com/shakacode/
|
19
|
+
2. Example repo of [React on Rails Tutorial With SSR, HMR fast refresh, and TypeScript](https://github.com/shakacode/react_on_rails_demo_ssr_hmr) for a new way to setup the creation of your SSR bundle with `rails/webpacker`.
|
20
20
|
3. Live, [open source](https://github.com/shakacode/react-webpack-rails-tutorial), example of this gem, see [reactrails.com](http://reactrails.com).
|
21
21
|
|
22
22
|
# Other Resources
|
@@ -51,6 +51,7 @@ module ReactOnRails
|
|
51
51
|
base_files = %w[babel.config.js
|
52
52
|
config/webpack/clientWebpackConfig.js
|
53
53
|
config/webpack/commonWebpackConfig.js
|
54
|
+
config/webpack/test.js
|
54
55
|
config/webpack/development.js
|
55
56
|
config/webpack/production.js
|
56
57
|
config/webpack/serverWebpackConfig.js
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/
|
1
|
+
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_demo_ssr_hmr/blob/master/babel.config.js") %>
|
2
2
|
|
3
3
|
module.exports = function (api) {
|
4
4
|
const defaultConfigFunc = require('shakapacker/package/babel/preset.js')
|
data/lib/generators/react_on_rails/templates/base/base/config/webpack/clientWebpackConfig.js.tt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/
|
1
|
+
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_demo_ssr_hmr/blob/master/config/webpack/clientWebpackConfig.js") %>
|
2
2
|
|
3
3
|
const commonWebpackConfig = require('./commonWebpackConfig');
|
4
4
|
|
data/lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/
|
1
|
+
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_demo_ssr_hmr/blob/master/config/webpack/commonWebpackConfig.js") %>
|
2
2
|
|
3
3
|
// Common configuration applying to client and server configuration
|
4
4
|
const { webpackConfig: baseClientWebpackConfig, merge } = require('shakapacker');
|
@@ -1,6 +1,4 @@
|
|
1
|
-
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/
|
2
|
-
|
3
|
-
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
1
|
+
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_demo_ssr_hmr/blob/master/config/webpack/development.js") %>
|
4
2
|
|
5
3
|
const { devServer, inliningCss } = require('shakapacker');
|
6
4
|
|
@@ -1,6 +1,4 @@
|
|
1
|
-
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/
|
2
|
-
|
3
|
-
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
|
1
|
+
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_demo_ssr_hmr/blob/master/config/webpack/production.js") %>
|
4
2
|
|
5
3
|
const webpackConfig = require('./webpackConfig');
|
6
4
|
|
data/lib/generators/react_on_rails/templates/base/base/config/webpack/serverWebpackConfig.js.tt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/
|
1
|
+
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_demo_ssr_hmr/blob/master/config/webpack/serverWebpackConfig.js") %>
|
2
2
|
|
3
3
|
const { merge, config } = require('shakapacker');
|
4
4
|
const commonWebpackConfig = require('./commonWebpackConfig');
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_demo_ssr_hmr/blob/master/config/webpack/test.js") %>
|
2
|
+
|
3
|
+
const webpackConfig = require('./webpackConfig')
|
4
|
+
|
5
|
+
const testOnly = (_clientWebpackConfig, _serverWebpackConfig) => {
|
6
|
+
// place any code here that is for test only
|
7
|
+
}
|
8
|
+
|
9
|
+
module.exports = webpackConfig(testOnly)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
const { env
|
1
|
+
const { env } = require('shakapacker')
|
2
2
|
const { existsSync } = require('fs')
|
3
3
|
const { resolve } = require('path')
|
4
4
|
|
@@ -8,7 +8,7 @@ const envSpecificConfig = () => {
|
|
8
8
|
console.log(`Loading ENV specific webpack configuration file ${path}`)
|
9
9
|
return require(path)
|
10
10
|
} else {
|
11
|
-
|
11
|
+
throw new Error(`Could not find file to load ${path}, based on NODE_ENV`)
|
12
12
|
}
|
13
13
|
}
|
14
14
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/
|
1
|
+
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_demo_ssr_hmr/blob/master/config/webpack/webpackConfig.js") %>
|
2
2
|
|
3
3
|
const clientWebpackConfig = require('./clientWebpackConfig');
|
4
4
|
const serverWebpackConfig = require('./serverWebpackConfig');
|
@@ -234,9 +234,9 @@ module ReactOnRails
|
|
234
234
|
console_log_script = result["consoleLogScript"]
|
235
235
|
raw("#{html}#{render_options.replay_console ? console_log_script : ''}")
|
236
236
|
rescue ExecJS::ProgramError => err
|
237
|
-
raise ReactOnRails::PrerenderError
|
238
|
-
|
239
|
-
|
237
|
+
raise ReactOnRails::PrerenderError.new(component_name: "N/A (server_render_js called)",
|
238
|
+
err: err,
|
239
|
+
js_code: js_code)
|
240
240
|
end
|
241
241
|
|
242
242
|
def json_safe_and_pretty(hash_or_string)
|
@@ -279,8 +279,9 @@ module ReactOnRails
|
|
279
279
|
# URLs as UTF-8. This situation can occur in browsers that do not encode the
|
280
280
|
# entire URL as UTF-8 already, mostly on the Windows platform (IE11 and lower).
|
281
281
|
original_url_normalized = request.original_url
|
282
|
-
if original_url_normalized.encoding
|
283
|
-
original_url_normalized = original_url_normalized.force_encoding(
|
282
|
+
if original_url_normalized.encoding == Encoding::BINARY
|
283
|
+
original_url_normalized = original_url_normalized.force_encoding(Encoding::ISO_8859_1)
|
284
|
+
.encode(Encoding::UTF_8)
|
284
285
|
end
|
285
286
|
|
286
287
|
# Using Addressable instead of standard URI to better deal with
|
@@ -309,6 +310,7 @@ module ReactOnRails
|
|
309
310
|
|
310
311
|
@rails_context.merge(serverSide: server_side)
|
311
312
|
end
|
313
|
+
|
312
314
|
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
313
315
|
|
314
316
|
private
|
@@ -483,21 +485,21 @@ module ReactOnRails
|
|
483
485
|
result = ReactOnRails::ServerRenderingPool.server_render_js_with_console_logging(js_code, render_options)
|
484
486
|
rescue StandardError => err
|
485
487
|
# This error came from the renderer
|
486
|
-
raise ReactOnRails::PrerenderError
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
488
|
+
raise ReactOnRails::PrerenderError.new(component_name: react_component_name,
|
489
|
+
# Sanitize as this might be browser logged
|
490
|
+
props: sanitized_props_string(props),
|
491
|
+
err: err,
|
492
|
+
js_code: js_code)
|
491
493
|
end
|
492
494
|
|
493
495
|
if result["hasErrors"] && render_options.raise_on_prerender_error
|
494
496
|
# We caught this exception on our backtrace handler
|
495
|
-
raise ReactOnRails::PrerenderError
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
497
|
+
raise ReactOnRails::PrerenderError.new(component_name: react_component_name,
|
498
|
+
# Sanitize as this might be browser logged
|
499
|
+
props: sanitized_props_string(props),
|
500
|
+
err: nil,
|
501
|
+
js_code: js_code,
|
502
|
+
console_messages: result["consoleReplayScript"])
|
501
503
|
|
502
504
|
end
|
503
505
|
result
|
@@ -49,10 +49,13 @@ module ReactOnRails
|
|
49
49
|
message = +"ERROR in SERVER PRERENDERING\n"
|
50
50
|
if err
|
51
51
|
message << <<~MSG
|
52
|
-
Encountered error:
|
52
|
+
Encountered error:
|
53
|
+
|
54
|
+
#{err}
|
55
|
+
|
53
56
|
MSG
|
54
57
|
|
55
|
-
backtrace = err.backtrace.join("\n")
|
58
|
+
backtrace = err.backtrace.first(15).join("\n")
|
56
59
|
else
|
57
60
|
backtrace = nil
|
58
61
|
end
|
@@ -47,7 +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
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity
|
51
51
|
def exec_server_render_js(js_code, render_options, js_evaluator = nil)
|
52
52
|
js_evaluator ||= self
|
53
53
|
if render_options.trace
|
@@ -56,12 +56,27 @@ module ReactOnRails
|
|
56
56
|
"tmp/server-generated-#{@file_index % 10}.js")
|
57
57
|
@file_index += 1
|
58
58
|
end
|
59
|
-
|
59
|
+
begin
|
60
|
+
json_string = js_evaluator.eval_js(js_code, render_options)
|
61
|
+
rescue StandardError => err
|
62
|
+
msg = <<~MSG
|
63
|
+
Error evaluating server bundle. Check your webpack configuration.
|
64
|
+
===============================================================
|
65
|
+
Caught error:
|
66
|
+
#{err.message}
|
67
|
+
===============================================================
|
68
|
+
MSG
|
69
|
+
|
70
|
+
if err.message.include?("ReferenceError: self is not defined")
|
71
|
+
msg << "\nError indicates that you may have code-splitting incorrectly enabled.\n"
|
72
|
+
end
|
73
|
+
raise ReactOnRails::Error, msg, err.backtrace
|
74
|
+
end
|
60
75
|
result = nil
|
61
76
|
begin
|
62
77
|
result = JSON.parse(json_string)
|
63
78
|
rescue JSON::ParserError => e
|
64
|
-
raise ReactOnRails::JsonParseError.new(e, json_string)
|
79
|
+
raise ReactOnRails::JsonParseError.new(parse_error: e, json: json_string)
|
65
80
|
end
|
66
81
|
|
67
82
|
if render_options.logging_on_server
|
@@ -76,7 +91,7 @@ module ReactOnRails
|
|
76
91
|
end
|
77
92
|
result
|
78
93
|
end
|
79
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
94
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity
|
80
95
|
|
81
96
|
def trace_js_code_used(msg, js_code, file_name = "tmp/server-generated.js", force: false)
|
82
97
|
return unless ReactOnRails.configuration.trace || force
|
data/package.json
CHANGED
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: 13.0.
|
4
|
+
version: 13.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Gordon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -248,6 +248,7 @@ files:
|
|
248
248
|
- lib/generators/react_on_rails/templates/base/base/config/webpack/development.js.tt
|
249
249
|
- lib/generators/react_on_rails/templates/base/base/config/webpack/production.js.tt
|
250
250
|
- lib/generators/react_on_rails/templates/base/base/config/webpack/serverWebpackConfig.js.tt
|
251
|
+
- lib/generators/react_on_rails/templates/base/base/config/webpack/test.js.tt
|
251
252
|
- lib/generators/react_on_rails/templates/base/base/config/webpack/webpack.config.js.tt
|
252
253
|
- lib/generators/react_on_rails/templates/base/base/config/webpack/webpackConfig.js.tt
|
253
254
|
- lib/generators/react_on_rails/templates/base/base/config/webpacker.yml
|
@@ -333,9 +334,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
333
334
|
version: 2.7.0
|
334
335
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
335
336
|
requirements:
|
336
|
-
- - "
|
337
|
+
- - ">="
|
337
338
|
- !ruby/object:Gem::Version
|
338
|
-
version:
|
339
|
+
version: '0'
|
339
340
|
requirements: []
|
340
341
|
rubygems_version: 3.2.32
|
341
342
|
signing_key:
|