react_on_rails 16.2.0.beta.3 → 16.2.0.beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +42 -5
  3. data/CLAUDE.md +59 -0
  4. data/CONTRIBUTING.md +49 -1
  5. data/Gemfile.development_dependencies +1 -1
  6. data/Gemfile.lock +25 -10
  7. data/SWITCHING_CI_CONFIGS.md +55 -6
  8. data/Steepfile +51 -0
  9. data/bin/ci-rerun-failures +68 -22
  10. data/bin/ci-run-failed-specs +26 -2
  11. data/bin/ci-switch-config +262 -34
  12. data/bin/lefthook/check-trailing-newlines +2 -12
  13. data/bin/lefthook/eslint-lint +0 -10
  14. data/bin/lefthook/prettier-format +0 -10
  15. data/bin/lefthook/ruby-autofix +3 -6
  16. data/knip.ts +35 -9
  17. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb.tt +32 -52
  18. data/lib/generators/react_on_rails/templates/base/base/config/shakapacker.yml +5 -1
  19. data/lib/react_on_rails/configuration.rb +56 -12
  20. data/lib/react_on_rails/controller.rb +3 -3
  21. data/lib/react_on_rails/dev/server_manager.rb +11 -4
  22. data/lib/react_on_rails/doctor.rb +249 -2
  23. data/lib/react_on_rails/helper.rb +12 -3
  24. data/lib/react_on_rails/pro_helper.rb +2 -44
  25. data/lib/react_on_rails/react_component/render_options.rb +7 -7
  26. data/lib/react_on_rails/utils.rb +40 -0
  27. data/lib/react_on_rails/version.rb +1 -1
  28. data/react_on_rails_pro/CHANGELOG.md +142 -29
  29. data/react_on_rails_pro/CONTRIBUTING.md +2 -13
  30. data/react_on_rails_pro/Gemfile.development_dependencies +1 -0
  31. data/react_on_rails_pro/Gemfile.lock +24 -3
  32. data/react_on_rails_pro/README.md +559 -38
  33. data/react_on_rails_pro/docs/code-splitting-loadable-components.md +1 -1
  34. data/react_on_rails_pro/docs/contributors-info/releasing.md +2 -2
  35. data/react_on_rails_pro/docs/installation.md +129 -109
  36. data/react_on_rails_pro/docs/node-renderer/basics.md +29 -22
  37. data/react_on_rails_pro/docs/node-renderer/error-reporting-and-tracing.md +8 -8
  38. data/react_on_rails_pro/docs/node-renderer/js-configuration.md +25 -23
  39. data/react_on_rails_pro/docs/node-renderer/troubleshooting.md +2 -0
  40. data/react_on_rails_pro/docs/updating.md +209 -15
  41. data/react_on_rails_pro/lib/react_on_rails_pro/concerns/stream.rb +58 -4
  42. data/react_on_rails_pro/lib/react_on_rails_pro/configuration.rb +17 -3
  43. data/react_on_rails_pro/lib/react_on_rails_pro/license_public_key.rb +9 -9
  44. data/react_on_rails_pro/lib/react_on_rails_pro/request.rb +41 -25
  45. data/react_on_rails_pro/lib/react_on_rails_pro/stream_request.rb +27 -7
  46. data/react_on_rails_pro/lib/react_on_rails_pro/utils.rb +3 -3
  47. data/react_on_rails_pro/lib/react_on_rails_pro/version.rb +1 -1
  48. data/react_on_rails_pro/package-scripts.yml +1 -1
  49. data/react_on_rails_pro/package.json +5 -8
  50. data/react_on_rails_pro/packages/node-renderer/src/integrations/api.ts +1 -1
  51. data/react_on_rails_pro/packages/node-renderer/src/master/restartWorkers.ts +39 -17
  52. data/react_on_rails_pro/packages/node-renderer/src/master.ts +15 -4
  53. data/react_on_rails_pro/packages/node-renderer/src/shared/configBuilder.ts +44 -5
  54. data/react_on_rails_pro/packages/node-renderer/src/shared/utils.ts +4 -2
  55. data/react_on_rails_pro/packages/node-renderer/src/worker/handleGracefulShutdown.ts +49 -0
  56. data/react_on_rails_pro/packages/node-renderer/src/worker/vm.ts +3 -3
  57. data/react_on_rails_pro/packages/node-renderer/src/worker.ts +5 -2
  58. data/react_on_rails_pro/packages/node-renderer/tests/helper.ts +8 -8
  59. data/react_on_rails_pro/packages/node-renderer/tests/testingNodeRendererConfigs.js +1 -1
  60. data/react_on_rails_pro/packages/node-renderer/tests/worker.test.ts +19 -19
  61. data/react_on_rails_pro/rakelib/public_key_management.rake +6 -5
  62. data/react_on_rails_pro/rakelib/rbs.rake +47 -0
  63. data/react_on_rails_pro/react_on_rails_pro.gemspec +1 -0
  64. data/react_on_rails_pro/sig/react_on_rails_pro/cache.rbs +13 -0
  65. data/react_on_rails_pro/sig/react_on_rails_pro/configuration.rbs +100 -0
  66. data/react_on_rails_pro/sig/react_on_rails_pro/error.rbs +4 -0
  67. data/react_on_rails_pro/sig/react_on_rails_pro/utils.rbs +7 -0
  68. data/react_on_rails_pro/sig/react_on_rails_pro.rbs +5 -0
  69. data/react_on_rails_pro/spec/dummy/Gemfile.lock +23 -3
  70. data/react_on_rails_pro/spec/dummy/app/controllers/pages_controller.rb +3 -3
  71. data/react_on_rails_pro/spec/dummy/bin/dev +4 -8
  72. data/react_on_rails_pro/spec/dummy/client/node-renderer.js +4 -4
  73. data/react_on_rails_pro/spec/dummy/config/environments/production.rb +1 -1
  74. data/react_on_rails_pro/spec/dummy/config/initializers/react_on_rails.rb +28 -12
  75. data/react_on_rails_pro/spec/dummy/config.ru +1 -1
  76. data/react_on_rails_pro/spec/dummy/package.json +2 -2
  77. data/react_on_rails_pro/spec/dummy/spec/helpers/react_on_rails_pro_helper_spec.rb +40 -11
  78. data/react_on_rails_pro/spec/dummy/spec/rails_helper.rb +1 -1
  79. data/react_on_rails_pro/spec/dummy/spec/requests/renderer_console_logging_spec.rb +5 -5
  80. data/react_on_rails_pro/spec/dummy/spec/system/integration_spec.rb +15 -10
  81. data/react_on_rails_pro/spec/dummy/spec/system/renderer_integration_spec.rb +3 -3
  82. data/react_on_rails_pro/spec/dummy/yarn.lock +4 -4
  83. data/react_on_rails_pro/spec/execjs-compatible-dummy/config/environments/production.rb +1 -1
  84. data/react_on_rails_pro/spec/execjs-compatible-dummy/config/initializers/react_on_rails.rb +16 -43
  85. data/react_on_rails_pro/spec/react_on_rails_pro/assets_precompile_spec.rb +15 -18
  86. data/react_on_rails_pro/spec/react_on_rails_pro/cache_spec.rb +1 -1
  87. data/react_on_rails_pro/spec/react_on_rails_pro/configuration_spec.rb +5 -3
  88. data/react_on_rails_pro/spec/react_on_rails_pro/license_validator_spec.rb +27 -12
  89. data/react_on_rails_pro/spec/react_on_rails_pro/request_spec.rb +0 -27
  90. data/react_on_rails_pro/spec/react_on_rails_pro/spec_helper.rb +1 -1
  91. data/react_on_rails_pro/spec/react_on_rails_pro/stream_decorator_spec.rb +89 -0
  92. data/react_on_rails_pro/spec/react_on_rails_pro/stream_spec.rb +144 -0
  93. data/react_on_rails_pro/spec/react_on_rails_pro/support/caching.rb +1 -1
  94. data/react_on_rails_pro/spec/react_on_rails_pro/support/mock_block_helper.rb +4 -2
  95. data/sig/react_on_rails/controller.rbs +1 -1
  96. data/sig/react_on_rails/error.rbs +4 -0
  97. data/sig/react_on_rails/helper.rbs +2 -2
  98. data/sig/react_on_rails/json_parse_error.rbs +10 -0
  99. data/sig/react_on_rails/prerender_error.rbs +21 -0
  100. data/sig/react_on_rails/smart_error.rbs +28 -0
  101. data/sig/react_on_rails.rbs +3 -24
  102. metadata +14 -4
  103. data/lib/react_on_rails/pro_utils.rb +0 -37
  104. data/react_on_rails_pro/spec/dummy/client/app/ror-auto-load-components/TestingStreamableComponent.jsx +0 -15
@@ -1,183 +1,203 @@
1
1
  # Installation
2
- Since the repository is private, you will get a **GitHub Personal Access Token** and an account that can access the packages. Substitute that value in the commands below. If you dont' have this, ask [justin@shakacode.com](mailto:justin@shakacode.com) to give you one.
3
2
 
4
- Check the [CHANGELOG](https://github.com/shakacode/react_on_rails_pro/blob/master/CHANGELOG.md) to see what version you want.
3
+ React on Rails Pro packages are published publicly on npmjs.org and RubyGems.org. Installation requires a valid **license token** for runtime validation. Contact [justin@shakacode.com](mailto:justin@shakacode.com) to purchase a license.
5
4
 
6
- # Version
5
+ **Upgrading from GitHub Packages?** See the [Upgrading Guide](./updating.md) for migration instructions.
7
6
 
8
- For the below docs, find the desired `<version>` in the CHANGELOG. Note, for pre-release versions, gems have all periods, and node packages uses a dash, like gem `3.0.0.rc.0` and node package `3.0.0-rc.0`.
7
+ Check the [CHANGELOG](https://github.com/shakacode/react_on_rails/blob/master/CHANGELOG.md) to see what version you want.
9
8
 
10
- # Ruby
11
- ## Gem Installation
12
- 1. Ensure your **Rails** app is using the **react_on_rails** gem, version greater than 11.0.7.
13
- 1. Add the `react_on_rails_pro` gem to your **Gemfile**. Substitute the appropriate version number.
14
-
15
- ## Gemfile Change
9
+ ## Version Format
16
10
 
17
- Replace the following in the snippet for the Gemfile
18
- 1. `<account>` for the api key
19
- 2. `<api-key>`
20
- 3. `<version>` desired
11
+ For the below docs, find the desired `<version>` in the CHANGELOG. Note that for pre-release versions:
12
+
13
+ - Gems use all periods: `16.2.0.beta.1`
14
+ - NPM packages use dashes: `16.2.0-beta.1`
15
+
16
+ # Ruby Gem Installation
17
+
18
+ ## Prerequisites
19
+
20
+ Ensure your **Rails** app is using the **react_on_rails** gem, version 16.0.0 or higher.
21
+
22
+ ## Install react_on_rails_pro Gem
23
+
24
+ Add the `react_on_rails_pro` gem to your **Gemfile**:
21
25
 
22
26
  ```ruby
23
- source "https://<rorp-account>:<token>@"\
24
- "rubygems.pkg.github.com/shakacode-tools" do
25
- gem "react_on_rails_pro", "<version>"
26
- end
27
+ gem "react_on_rails_pro", "~> 16.2"
27
28
  ```
28
29
 
29
- ## Alternate installation keeping the key out of your Gemfile
30
+ Then run:
30
31
 
31
- ```ruby
32
- source "https://rubygems.pkg.github.com/shakacode-tools" do
33
- gem "react_on_rails_pro", "<version>"
34
- end
32
+ ```bash
33
+ bundle install
35
34
  ```
36
- Or use the `gem install` command:
35
+
36
+ Or install directly:
37
37
 
38
38
  ```bash
39
- gem install react_on_rails_pro --version "<version>> --source "https://rubygems.pkg.github.com/shakacode-tools"
39
+ gem install react_on_rails_pro --version "<version>"
40
40
  ```
41
41
 
42
- Then edit your permissions for bundler at the command line:
42
+ ## License Configuration
43
43
 
44
+ Set your license token as an environment variable:
45
+
46
+ ```bash
47
+ export REACT_ON_RAILS_PRO_LICENSE="your-license-token-here"
44
48
  ```
45
- bundle config set rubygems.pkg.github.com <username>:<token>
49
+
50
+ Or configure it in your Rails initializer (not recommended for production):
51
+
52
+ ```ruby
53
+ # config/initializers/react_on_rails_pro.rb
54
+ ReactOnRailsPro.configure do |config|
55
+ config.license_token = ENV["REACT_ON_RAILS_PRO_LICENSE"]
56
+ end
46
57
  ```
47
58
 
48
- ## Using a branch in your Gemfile
49
- Note, you should probably use an ENV value for the token so that you don't check this into your source code.
50
- ```ruby
51
- gem "react_on_rails_pro", version: "<version>", git: "https://[your-github-token]:x-oauth-basic@github.com/shakacode/react_on_rails_pro.git", tag: "<version>"
52
- ```
59
+ ⚠️ **Security Warning**: Never commit your license token to version control. Always use environment variables or secure secret management systems (like Rails credentials, Heroku config vars, AWS Secrets Manager, etc.).
53
60
 
54
61
  ## Rails Configuration
55
- You don't need to create an initializer if you are satisfied with the default as described in
56
- [Configuration](./configuration.md)
57
62
 
58
- # Node Package
59
- Note, you only need to install the Node Package if you are using the standalone node renderer, `NodeRenderer`.
63
+ You don't need to create an initializer if you are satisfied with the defaults as described in [Configuration](./configuration.md).
60
64
 
61
- ## Installation
65
+ For basic setup:
62
66
 
63
- 1. Create a subdirectory of your rails project for the Node renderer. Let's use `react-on-rails-pro`.
64
-
65
- 2. Create a file `react-on-rails-pro/.npmrc` with the following
67
+ ```ruby
68
+ # config/initializers/react_on_rails_pro.rb
69
+ ReactOnRailsPro.configure do |config|
70
+ # Your configuration here
71
+ # See docs/configuration.md for all options
72
+ end
66
73
  ```
67
- always-auth=true
68
- //npm.pkg.github.com/:_authToken=<token>
69
- @shakacode-tools:registry=https://npm.pkg.github.com
74
+
75
+ # Node Package Installation
76
+
77
+ **Note:** You only need to install the Node Package if you are using the standalone node renderer (`NodeRenderer`). If you're using `ExecJS` (the default), skip this section.
78
+
79
+ ## Install react-on-rails-pro-node-renderer
80
+
81
+ ### Using npm:
82
+
83
+ ```bash
84
+ npm install react-on-rails-pro-node-renderer
85
+ ```
86
+
87
+ ### Using yarn:
88
+
89
+ ```bash
90
+ yarn add react-on-rails-pro-node-renderer
70
91
  ```
71
92
 
72
- 3. Create a `react-on-rails-pro/package.json`
93
+ ### Add to package.json:
94
+
73
95
  ```json
74
96
  {
75
- "private": true,
76
97
  "dependencies": {
77
- "@shakacode-tools/react-on-rails-pro-node-renderer": "<version>"
78
- },
79
- "scripts": {
80
- "node-renderer": "echo 'Starting React on Rails Pro Node Renderer.' && node ./react-on-rails-pro-node-renderer.js"
98
+ "react-on-rails-pro-node-renderer": "^16.2.0"
81
99
  }
82
100
  }
83
101
  ```
84
102
 
85
- 4. Be sure to run `npm i` **and not** `yarn` as only npm seems to work with the private github packages.
103
+ ## Node Renderer Setup
86
104
 
87
- If you really want to use yarn, see [Yarn can't find private Github npm registry](https://stackoverflow.com/questions/58316109/yarn-cant-find-private-github-npm-registry)
88
-
89
- 5. You can start the renderer with either the executable `node-renderer` or, preferably, with
90
- a startup JS file, say called `react-on-rails-pro/react-on-rails-pro-node-renderer.js` with
91
- these contents. _Note the use of the namespaced **`@shakacode-tools/react-on-rails-pro-node-renderer`** for the package.
105
+ Create a JavaScript file to configure and launch the node renderer, for example `react-on-rails-pro-node-renderer.js`:
92
106
 
93
107
  ```js
94
- const path = require('path')
95
- const {
96
- reactOnRailsProNodeRenderer,
97
- } = require('@shakacode-tools/react-on-rails-pro-node-renderer')
108
+ const path = require('path');
109
+ const { reactOnRailsProNodeRenderer } = require('react-on-rails-pro-node-renderer');
98
110
 
99
- const env = process.env
111
+ const env = process.env;
100
112
 
101
113
  const config = {
102
- bundlePath: path.resolve(__dirname, '../.node-renderer-bundles'),
114
+ serverBundleCachePath: path.resolve(__dirname, '../.node-renderer-bundles'),
103
115
 
104
116
  // Listen at RENDERER_PORT env value or default port 3800
105
117
  logLevel: env.RENDERER_LOG_LEVEL || 'debug', // show all logs
106
118
 
107
- // See value in /config/initializers/react_on_rails_pro.rb. Should use env
108
- // value in real app.
109
- password: 'myPassword1',
119
+ // Password for Rails <-> Node renderer communication
120
+ // See value in /config/initializers/react_on_rails_pro.rb
121
+ password: env.RENDERER_PASSWORD || 'changeme',
110
122
 
111
- // Save bundle to "tmp/bundles" dir of our dummy app
112
- // This is the default
113
123
  port: env.RENDERER_PORT || 3800,
114
124
 
115
125
  // supportModules should be set to true to allow the server-bundle code to
116
- // see require, exports, etc.
117
- // `false` is like the ExecJS behavior
118
- // this option is required to equal `true` in order to use loadable components
126
+ // see require, exports, etc. (`false` is like the ExecJS behavior)
127
+ // This option is required to equal `true` in order to use loadable components
119
128
  supportModules: true,
120
129
 
121
130
  // workersCount defaults to the number of CPUs minus 1
122
- workersCount: Number(process.env.NODE_RENDERER_CONCURRENCY || 3),
123
-
124
- // Next 2 params, allWorkersRestartInterval and
125
- // delayBetweenIndividualWorkerRestarts must both should be set if you wish
126
- // to have automatic worker restarting, say to clear memory leaks.
127
- // time is in minutes between restarting all workers
128
- // Enable next 2 if the renderer is running out of memory
129
- // allWorkersRestartInterval: 15,
130
- // time in minutes between each worker restarting when restarting all workers
131
- // delayBetweenIndividualWorkerRestarts: 2,
132
- }
131
+ workersCount: Number(env.NODE_RENDERER_CONCURRENCY || 3),
132
+
133
+ // Optional: Automatic worker restarting (for memory leak mitigation)
134
+ // allWorkersRestartInterval: 15, // minutes between restarting all workers
135
+ // delayBetweenIndividualWorkerRestarts: 2, // minutes between each worker restart
136
+ // gracefulWorkerRestartTimeout: undefined, // timeout for graceful worker restart; forces restart if worker stuck
137
+ };
133
138
 
134
139
  // Renderer detects a total number of CPUs on virtual hostings like Heroku
135
140
  // or CircleCI instead of CPUs number allocated for current container. This
136
141
  // results in spawning many workers while only 1-2 of them really needed.
137
142
  if (env.CI) {
138
- config.workersCount = 2
143
+ config.workersCount = 2;
139
144
  }
140
145
 
141
- reactOnRailsProNodeRenderer(config)
146
+ reactOnRailsProNodeRenderer(config);
142
147
  ```
143
148
 
144
- ## Instructions for using a branch
149
+ Add a script to your `package.json`:
145
150
 
146
- Install the node-renderer executable, possibly globally. Substitute the branch name or tag for `master`
151
+ ```json
152
+ {
153
+ "scripts": {
154
+ "node-renderer": "node ./react-on-rails-pro-node-renderer.js"
155
+ }
156
+ }
147
157
  ```
148
- yarn global add https://<your-github-token>:x-oauth-basic@github.com/shakacode/react_on_rails_pro.git\#master
158
+
159
+ Start the renderer:
160
+
161
+ ```bash
162
+ npm run node-renderer
149
163
  ```
150
164
 
151
- This installs a binary `node-renderer`.
165
+ ## Rails Configuration for Node Renderer
152
166
 
153
- ### Using Github packages
167
+ Configure Rails to use the remote node renderer:
154
168
 
155
- Login into npm
169
+ ```ruby
170
+ # config/initializers/react_on_rails_pro.rb
171
+ ReactOnRailsPro.configure do |config|
172
+ config.server_renderer = "NodeRenderer"
156
173
 
157
- ```bash
158
- npm install @shakacode-tools/react-on-rails-pro-node-renderer@<version>
159
- ```
174
+ # Configure renderer connection
175
+ config.renderer_url = ENV["REACT_RENDERER_URL"] || "http://localhost:3800"
176
+ config.renderer_password = ENV["RENDERER_PASSWORD"] || "changeme"
160
177
 
161
- or edit package.json directly
162
- ```json
163
- "@shakacode-tools/react-on-rails-pro-node-renderer": "<version>"
164
- ```
178
+ # Enable prerender caching (recommended)
179
+ config.prerender_caching = true
180
+ end
181
+ ```
165
182
 
166
- ### Configuration
167
- See [NodeRenderer JavaScript Configuration](./node-renderer/js-configuration.md).
183
+ ### Configuration Options
168
184
 
169
- #### Webpack Configuration
170
- Set your server bundle webpack configuration to use a target of `node` per the [Webpack docs](https://webpack.js.org/concepts/targets/#usage).
185
+ See [Rails Configuration Options](./configuration.md) for all available settings.
171
186
 
172
- ## Authentication when using Github packages
173
- [Auth for the npm package](https://docs.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-npm-for-use-with-github-packages#authenticating-to-github-packages)
187
+ Pay attention to:
174
188
 
175
- Create a new ~/.npmrc file if one doesn't exist.
176
- ```
177
- //npm.pkg.github.com/:_authToken=TOKEN
178
- ```
189
+ - `config.server_renderer = "NodeRenderer"` - Required to use node renderer
190
+ - `config.renderer_url` - URL where your node renderer is running
191
+ - `config.renderer_password` - Shared secret for authentication
192
+ - `config.prerender_caching` - Enable caching (recommended)
179
193
 
180
- To configure bundler if you don't want the token in your Gemfile:
181
- ```
182
- bundle config https://rubygems.pkg.github.com/OWNER USERNAME:TOKEN
183
- ```
194
+ ## Webpack Configuration
195
+
196
+ Set your server bundle webpack configuration to use a target of `node` per the [Webpack docs](https://webpack.js.org/concepts/targets/#usage).
197
+
198
+ ## Additional Documentation
199
+
200
+ - [Node Renderer Basics](./node-renderer/basics.md)
201
+ - [Node Renderer JavaScript Configuration](./node-renderer/js-configuration.md)
202
+ - [Rails Configuration Options](./configuration.md)
203
+ - [Error Reporting and Tracing](./node-renderer/error-reporting-and-tracing.md)
@@ -1,23 +1,26 @@
1
1
  # Requirements
2
- * You must use React on Rails v11.0.7 or higher.
2
+
3
+ - You must use React on Rails v11.0.7 or higher.
3
4
 
4
5
  # Install the Gem and the Node Module
6
+
5
7
  See [Installation](../installation.md).
6
8
 
7
9
  # Setup Node Renderer Server
10
+
8
11
  **node-renderer** is a standalone Node application to serve React SSR requests from a **Rails** client. You don't need any **Ruby** code to setup and launch it. You can configure with the command line or with a launch file.
9
12
 
10
13
  ## Simple Command Line for node-renderer
11
14
 
12
15
  1. ENV values for the default config are (See [JS Configuration](./js-configuration.md) for more details):
13
- * `RENDERER_PORT`
14
- * `RENDERER_LOG_LEVEL`
15
- * `RENDERER_BUNDLE_PATH`
16
- * `RENDERER_WORKERS_COUNT`
17
- * `RENDERER_PASSWORD`
18
- * `RENDERER_ALL_WORKERS_RESTART_INTERVAL`
19
- * `RENDERER_DELAY_BETWEEN_INDIVIDUAL_WORKER_RESTARTS`
20
- * `RENDERER_SUPPORT_MODULES`
16
+ - `RENDERER_PORT`
17
+ - `RENDERER_LOG_LEVEL`
18
+ - `RENDERER_BUNDLE_PATH`
19
+ - `RENDERER_WORKERS_COUNT`
20
+ - `RENDERER_PASSWORD`
21
+ - `RENDERER_ALL_WORKERS_RESTART_INTERVAL`
22
+ - `RENDERER_DELAY_BETWEEN_INDIVIDUAL_WORKER_RESTARTS`
23
+ - `RENDERER_SUPPORT_MODULES`
21
24
  2. Configure ENV values and run the command. Note, you can set port with args `-p <PORT>`. For example, assuming node-renderer is in your path:
22
25
  ```
23
26
  RENDERER_BUNDLE_PATH=/app/.node-renderer-bundles node-renderer
@@ -25,6 +28,7 @@ See [Installation](../installation.md).
25
28
  3. You can use a command line argument of `-p SOME_PORT` to override any ENV value for the PORT.
26
29
 
27
30
  ## JavaScript Configuration File
31
+
28
32
  For the most control over the setup, create a JavaScript file to start the NodeRenderer.
29
33
 
30
34
  1. Create some project directory, let's say `renderer-app`:
@@ -33,27 +37,29 @@ For the most control over the setup, create a JavaScript file to start the NodeR
33
37
  cd renderer-app
34
38
  ```
35
39
  2. Make sure you have **Node.js** version **14** or higher and **Yarn** installed.
36
- 3. Init node application and yarn add to install `@shakacode-tools/react-on-rails-pro-node-renderer` package.
40
+ 3. Init node application and install the `react-on-rails-pro-node-renderer` package.
37
41
  ```sh
38
42
  yarn init
39
- yarn add https://[your-github-token]:x-oauth-basic@github.com/shakacode/react_on_rails_pro.git\#master
43
+ yarn add react-on-rails-pro-node-renderer
40
44
  ```
41
- 4. Configure a JavaScript file that will launch the rendering server per the docs in [Node Renderer JavaScript Configuration](./js-configuration.md). For example, create a file `node-renderer.js`. Here is a simple example that uses all the defaults except for bundlePath:
45
+ 4. Configure a JavaScript file that will launch the rendering server per the docs in [Node Renderer JavaScript Configuration](./js-configuration.md). For example, create a file `node-renderer.js`. Here is a simple example that uses all the defaults except for serverBundleCachePath:
42
46
 
43
47
  ```javascript
44
48
  import path from 'path';
45
- import reactOnRailsProNodeRenderer from '@shakacode-tools/react-on-rails-pro-node-renderer';
49
+ import reactOnRailsProNodeRenderer from 'react-on-rails-pro-node-renderer';
46
50
 
47
51
  const config = {
48
- bundlePath: path.resolve(__dirname, '../.node-renderer-bundles'),
52
+ serverBundleCachePath: path.resolve(__dirname, '../.node-renderer-bundles'),
49
53
  };
50
54
 
51
55
  reactOnRailsProNodeRenderer(config);
52
56
  ```
57
+
53
58
  5. Now you can launch your renderer server with `node node-renderer.js`. You will probably add a script to your `package.json`.
54
59
  6. You can use a command line argument of `-p SOME_PORT` to override any configured or ENV value for the port.
55
60
 
56
61
  # Setup Rails Application
62
+
57
63
  Create `config/initializers/react_on_rails_pro.rb` and configure the **renderer server**. See configuration values in [Configuration](../configuration.md). Pay attention to:
58
64
 
59
65
  1. Set `config.server_renderer = "NodeRenderer"`
@@ -61,25 +67,26 @@ Create `config/initializers/react_on_rails_pro.rb` and configure the **renderer
61
67
  3. Configure values beginning with `renderer_`
62
68
  4. Use ENV values for values like `renderer_url` so that your deployed server is properly configured. If the ENV value is unset, the default for the renderer_url is `localhost:3800`.
63
69
  5. Here's a tiny example using mostly defaults:
70
+
64
71
  ```ruby
65
72
  ReactOnRailsPro.configure do |config|
66
73
  config.server_renderer = "NodeRenderer"
67
-
68
- # when this ENV value is not defined, the local server at localhost:3800 is used
69
- config.renderer_url = ENV["REACT_RENDERER_URL"]
74
+
75
+ # when this ENV value is not defined, the local server at localhost:3800 is used
76
+ config.renderer_url = ENV["REACT_RENDERER_URL"]
70
77
  end
71
78
  ```
72
79
 
73
80
  ## Troublshooting
74
81
 
75
- * See [JS Memory Leaks](../js-memory-leaks.md).
76
-
82
+ - See [JS Memory Leaks](../js-memory-leaks.md).
83
+
77
84
  ## Upgrading
78
85
 
79
86
  The NodeRenderer has a protocol version on both the Rails and Node sides. If the Rails server sends a protocol version that does not match the Node side, an error is returned. Ideally, you want to keep both the Rails and Node sides at the same version.
80
87
 
81
88
  ## References
82
89
 
83
- * [Installation](../installation.md).
84
- * [Rails Options for node-renderer](../configuration.md)
85
- * [JS Options for node-renderer](./js-configuration.md)
90
+ - [Installation](../installation.md).
91
+ - [Rails Options for node-renderer](../configuration.md)
92
+ - [JS Options for node-renderer](./js-configuration.md)
@@ -14,10 +14,10 @@ It should initialize the services according to your requirements and then enable
14
14
  3. Then load the integration:
15
15
 
16
16
  ```js
17
- require('@shakacode-tools/react-on-rails-pro-node-renderer/integrations/sentry').init();
17
+ require('react-on-rails-pro-node-renderer/integrations/sentry').init();
18
18
  ```
19
19
 
20
- - Use `@shakacode-tools/react-on-rails-pro-node-renderer/integrations/sentry6` instead of `.../sentry` for versions of Sentry SDK older than 7.63.0.
20
+ - Use `react-on-rails-pro-node-renderer/integrations/sentry6` instead of `.../sentry` for versions of Sentry SDK older than 7.63.0.
21
21
  - For Sentry SDK v8+ you can use `.init({ fastify: true })` to capture additional Fastify-related information.
22
22
 
23
23
  ### Sentry Tracing
@@ -40,7 +40,7 @@ To enable Sentry Tracing:
40
40
  2. Then load the integration:
41
41
 
42
42
  ```js
43
- require('@shakacode-tools/react-on-rails-pro-node-renderer/integrations/honeybadger').init();
43
+ require('react-on-rails-pro-node-renderer/integrations/honeybadger').init();
44
44
  ```
45
45
 
46
46
  Use `init({ fastify: true })` to capture additional Fastify-related information.
@@ -49,7 +49,7 @@ To enable Sentry Tracing:
49
49
  You can create your own integrations in the same way as the provided ones.
50
50
  If you have access to the React on Rails Pro repository,
51
51
  you can use [their implementations](https://github.com/shakacode/react_on_rails_pro/tree/master/packages/node-renderer/src/integrations) as examples.
52
- Import these functions from `@shakacode-tools/react-on-rails-pro-node-renderer/integrations/api`:
52
+ Import these functions from `react-on-rails-pro-node-renderer/integrations/api`:
53
53
 
54
54
  ### Error reporting services
55
55
 
@@ -59,7 +59,7 @@ Import these functions from `@shakacode-tools/react-on-rails-pro-node-renderer/i
59
59
  For example, integrating with BugSnag can be as simple as
60
60
  ```js
61
61
  const Bugsnag = require('@bugsnag/js');
62
- const { addNotifier } = require('@shakacode-tools/react-on-rails-pro-node-renderer/integrations/api');
62
+ const { addNotifier } = require('react-on-rails-pro-node-renderer/integrations/api');
63
63
 
64
64
  Bugsnag.start({ /* your options */ });
65
65
 
@@ -76,7 +76,7 @@ To track requests as [sessions](https://docs.bugsnag.com/platforms/javascript/ca
76
76
  the above example becomes
77
77
  ```js
78
78
  const Bugsnag = require('@bugsnag/js');
79
- const { addNotifier, setupTracing } = require('@shakacode-tools/react-on-rails-pro-node-renderer/integrations/api');
79
+ const { addNotifier, setupTracing } = require('react-on-rails-pro-node-renderer/integrations/api');
80
80
 
81
81
  Bugsnag.start({ /* your options */ });
82
82
 
@@ -117,7 +117,7 @@ Bugsnag v7 is a bit more complicated:
117
117
 
118
118
  ```js
119
119
  const Bugsnag = require('@bugsnag/js');
120
- const { addNotifier, setupTracing } = require('@shakacode-tools/react-on-rails-pro-node-renderer/integrations/api');
120
+ const { addNotifier, setupTracing } = require('react-on-rails-pro-node-renderer/integrations/api');
121
121
 
122
122
  Bugsnag.start({ /* your options */ });
123
123
 
@@ -142,7 +142,7 @@ If you want to report HTTP requests from Fastify, you can use `configureFastify`
142
142
  Extending the above example:
143
143
 
144
144
  ```js
145
- const { configureFastify } = require('@shakacode-tools/react-on-rails-pro-node-renderer/integrations/api');
145
+ const { configureFastify } = require('react-on-rails-pro-node-renderer/integrations/api');
146
146
 
147
147
  configureFastify((app) => {
148
148
  app.addHook('onError', (_req, _reply, error, done) => {
@@ -8,39 +8,41 @@ The values in this file must be kept in sync with with the `config/initializers/
8
8
 
9
9
  Here are the options available for the JavaScript renderer configuration object, as well as the available default ENV values if using the command line program node-renderer.
10
10
 
11
- [//]: # (If you change text here, you may want to update comments in packages/node-renderer/src/shared/configBuilder.ts as well.)
11
+ [//]: # 'If you change text here, you may want to update comments in packages/node-renderer/src/shared/configBuilder.ts as well.'
12
12
 
13
13
  1. **port** (default: `process.env.RENDERER_PORT || 3800`) - The port the renderer should listen to.
14
- [On Heroku](https://devcenter.heroku.com/articles/dyno-startup-behavior#port-binding-of-web-dynos) or [ControlPlane](https://docs.controlplane.com/reference/workload/containers#port-variable) you may want to use `process.env.PORT`.
14
+ [On Heroku](https://devcenter.heroku.com/articles/dyno-startup-behavior#port-binding-of-web-dynos) or [ControlPlane](https://docs.controlplane.com/reference/workload/containers#port-variable) you may want to use `process.env.PORT`.
15
15
  1. **logLevel** (default: `process.env.RENDERER_LOG_LEVEL || 'info'`) - The renderer log level. Set it to `silent` to turn logging off.
16
- [Available levels](https://getpino.io/#/docs/api?id=levels): `{ fatal: 60, error: 50, warn: 40, info: 30, debug: 20, trace: 10 }`. `silent` can be used as well.
16
+ [Available levels](https://getpino.io/#/docs/api?id=levels): `{ fatal: 60, error: 50, warn: 40, info: 30, debug: 20, trace: 10 }`. `silent` can be used as well.
17
17
  1. **logHttpLevel** (default: `process.env.RENDERER_LOG_HTTP_LEVEL || 'error'`) - The HTTP server log level (same allowed values as `logLevel`).
18
18
  1. **fastifyServerOptions** (default: `{}`) - Additional options to pass to the Fastify server factory. See [Fastify documentation](https://fastify.dev/docs/latest/Reference/Server/#factory).
19
- 1. **bundlePath** (default: `process.env.RENDERER_BUNDLE_PATH || '/tmp/react-on-rails-pro-node-renderer-bundles'` ) - path to a temp directory where uploaded bundle files will be stored. For example you can set it to `path.resolve(__dirname, './.node-renderer-bundles')` if you configured renderer from the `/` directory of your app.
19
+ 1. **serverBundleCachePath** (default: `process.env.RENDERER_SERVER_BUNDLE_CACHE_PATH || process.env.RENDERER_BUNDLE_PATH || '/tmp/react-on-rails-pro-node-renderer-bundles'` ) - Path to a cache directory where uploaded server bundle files will be stored. This is distinct from Shakapacker's public asset directory. For example you can set it to `path.resolve(__dirname, './.node-renderer-bundles')` if you configured renderer from the `/` directory of your app.
20
20
  1. **workersCount** (default: `process.env.RENDERER_WORKERS_COUNT || defaultWorkersCount()` where default is your CPUs count - 1) - Number of workers that will be forked to serve rendering requests. If you set this manually make sure that value is a **Number** and is `>= 0`. Setting this to `0` will run the renderer in a single process mode without forking any workers, which is useful for debugging purposes. For production use, the value should be `>= 1`.
21
21
  1. **password** (default: `env.RENDERER_PASSWORD`) - The password expected to receive from the **Rails client** to authenticate rendering requests.
22
- If no password is set, no authentication will be required.
22
+ If no password is set, no authentication will be required.
23
23
  1. **allWorkersRestartInterval** (default: `env.RENDERER_ALL_WORKERS_RESTART_INTERVAL`) - Interval in minutes between scheduled restarts of all workers. By default restarts are not enabled. If restarts are enabled, `delayBetweenIndividualWorkerRestarts` should also be set.
24
24
  1. **delayBetweenIndividualWorkerRestarts** (default: `env.RENDERER_DELAY_BETWEEN_INDIVIDUAL_WORKER_RESTARTS`) - Interval in minutes between individual worker restarts (when cluster restart is triggered). By default restarts are not enabled. If restarts are enabled, `allWorkersRestartInterval` should also be set.
25
+ 1. **gracefulWorkerRestartTimeout**: (default: `env.GRACEFUL_WORKER_RESTART_TIMEOUT`) - Time in seconds that the master waits for a worker to gracefully restart (after serving all active requests) before killing it. Use this when you want to avoid situations where a worker gets stuck in an infinite loop and never restarts. This config is only usable if worker restart is enabled. The timeout starts when the worker should restart; if it elapses without a restart, the worker is killed.
25
26
  1. **maxDebugSnippetLength** (default: 1000) - If the rendering request is longer than this, it will be truncated in exception and logging messages.
26
- 1. **supportModules** - (default: `env.RENDERER_SUPPORT_MODULES || null`) - If set to true, `supportModules` enables the server-bundle code to call a default set of NodeJS global objects and functions that get added to the VM context:
27
- `{ Buffer, TextDecoder, TextEncoder, URLSearchParams, ReadableStream, process, setTimeout, setInterval, setImmediate, clearTimeout, clearInterval, clearImmediate, queueMicrotask }`.
28
- This option is required to equal `true` if you want to use loadable components.
29
- Setting this value to false causes the NodeRenderer to behave like ExecJS.
30
- See also `stubTimers`.
31
- 1. **additionalContext** - (default: `null`) - additionalContext enables you to specify additional NodeJS objects (usually from https://nodejs.org/api/globals.html) to add to the VM context in addition to our `supportModules` defaults.
32
- Object shorthand notation may be used, but is not required.
33
- Example: `{ URL, Crypto }`
34
- 1. **stubTimers** - (default: `env.RENDERER_STUB_TIMERS` if that environment variable is set, `true` otherwise) - With this option set, use of functions `setTimeout`, `setInterval`, `setImmediate`, `clearTimeout`, `clearInterval`, `clearImmediate`, and `queueMicrotask` will do nothing during server-rendering.
35
- This is useful when using dependencies like [react-virtuoso](https://github.com/petyosi/react-virtuoso) that use these functions during hydration.
36
- In RORP, hydration typically is synchronous and single-task (unless you use streaming) and thus callbacks passed to task-scheduling functions should never run during server-side rendering.
37
- Because these functions are valid client-side, they are ignored on server-side rendering without errors or warnings.
38
- See also `supportModules`.
27
+ 1. **supportModules** - (default: `env.RENDERER_SUPPORT_MODULES || null`) - If set to true, `supportModules` enables the server-bundle code to call a default set of NodeJS global objects and functions that get added to the VM context:
28
+ `{ Buffer, TextDecoder, TextEncoder, URLSearchParams, ReadableStream, process, setTimeout, setInterval, setImmediate, clearTimeout, clearInterval, clearImmediate, queueMicrotask }`.
29
+ This option is required to equal `true` if you want to use loadable components.
30
+ Setting this value to false causes the NodeRenderer to behave like ExecJS.
31
+ See also `stubTimers`.
32
+ 1. **additionalContext** - (default: `null`) - additionalContext enables you to specify additional NodeJS objects (usually from https://nodejs.org/api/globals.html) to add to the VM context in addition to our `supportModules` defaults.
33
+ Object shorthand notation may be used, but is not required.
34
+ Example: `{ URL, Crypto }`
35
+ 1. **stubTimers** - (default: `env.RENDERER_STUB_TIMERS` if that environment variable is set, `true` otherwise) - With this option set, use of functions `setTimeout`, `setInterval`, `setImmediate`, `clearTimeout`, `clearInterval`, `clearImmediate`, and `queueMicrotask` will do nothing during server-rendering.
36
+ This is useful when using dependencies like [react-virtuoso](https://github.com/petyosi/react-virtuoso) that use these functions during hydration.
37
+ In RORP, hydration typically is synchronous and single-task (unless you use streaming) and thus callbacks passed to task-scheduling functions should never run during server-side rendering.
38
+ Because these functions are valid client-side, they are ignored on server-side rendering without errors or warnings.
39
+ See also `supportModules`.
39
40
 
40
41
  Deprecated options:
41
42
 
42
- 1. **honeybadgerApiKey**, **sentryDsn**, **sentryTracing**, **sentryTracesSampleRate** - Deprecated and have no effect.
43
- If you have any of them set, see [Error Reporting and Tracing](./error-reporting-and-tracing.md) for the new way to set up error reporting and tracing.
43
+ 1. **bundlePath** - Renamed to `serverBundleCachePath`. The old name will continue to work but will log a deprecation warning.
44
+ 1. **honeybadgerApiKey**, **sentryDsn**, **sentryTracing**, **sentryTracesSampleRate** - Deprecated and have no effect.
45
+ If you have any of them set, see [Error Reporting and Tracing](./error-reporting-and-tracing.md) for the new way to set up error reporting and tracing.
44
46
  1. **includeTimerPolyfills** - Renamed to `stubTimers`.
45
47
 
46
48
  ## Example Launch Files
@@ -52,13 +54,14 @@ If you have any of them set, see [Error Reporting and Tracing](./error-reporting
52
54
  ### Simple example:
53
55
 
54
56
  Create a file './node-renderer.js'
57
+
55
58
  ```js
56
59
  import path from 'path';
57
- import { reactOnRailsProNodeRenderer } from '@shakacode-tools/react-on-rails-pro-node-renderer';
60
+ import { reactOnRailsProNodeRenderer } from 'react-on-rails-pro-node-renderer';
58
61
 
59
62
  const config = {
60
63
  // Save bundles to relative "./.node-renderer-bundles" dir of our app
61
- bundlePath: path.resolve(__dirname, './.node-renderer-bundles'),
64
+ serverBundleCachePath: path.resolve(__dirname, './.node-renderer-bundles'),
62
65
 
63
66
  // All other values are the defaults, as described above
64
67
  };
@@ -75,7 +78,6 @@ else if (process.env.CI) {
75
78
  }
76
79
 
77
80
  reactOnRailsProNodeRenderer(config);
78
-
79
81
  ```
80
82
 
81
83
  And add this line to your `scripts` section of `package.json`
@@ -1,3 +1,5 @@
1
1
  # Node Renderer Troubleshooting
2
2
 
3
3
  - If you enabled restarts (having `allWorkersRestartInterval` and `delayBetweenIndividualWorkerRestarts`), you should set it with a high number to avoid the app from crashing because all Node renderer workers are stopped/killed.
4
+
5
+ - If your app contains streamed pages that take too much time to be streamed to the client, ensure to not set the `gracefulWorkerRestartTimeout` parameter or set to a high number, so the worker is not killed while it's still serving an active request.