Skip to content

Commit fffa737

Browse files
justin808claude
andauthored
Rename bundlePath to serverBundleCachePath in node renderer (#2008)
## Summary This PR renames the `bundlePath` configuration option to `serverBundleCachePath` in the node renderer to better describe its purpose and avoid confusion with Shakapacker's public bundle path. ## Changes - **Config interface**: Added `serverBundleCachePath` as the new property, deprecated `bundlePath` - **Deprecation handling**: Added warning messages when the old name is used (both config and env var) - **Environment variables**: Support both `RENDERER_SERVER_BUNDLE_CACHE_PATH` (new) and `RENDERER_BUNDLE_PATH` (deprecated) - **Internal code**: Updated all internal code to use `serverBundleCachePath` - **Documentation**: Updated all docs and examples to use the new name - **Tests**: Updated test files and helper functions to use the new name - **Backwards compatibility**: The old `bundlePath` option continues to work with deprecation warnings ## Why this change? The name `bundlePath` was confusing because: 1. It could be confused with Shakapacker's public bundle path (where client-side assets are served) 2. It didn't clearly indicate that this is a **cache directory** for **uploaded server bundles** 3. The new name `serverBundleCachePath` makes the purpose explicit ## Migration guide Users can update their configuration: **Before:** ```js const config = { bundlePath: path.resolve(__dirname, './.node-renderer-bundles'), }; ``` **After:** ```js const config = { serverBundleCachePath: path.resolve(__dirname, './.node-renderer-bundles'), }; ``` **Environment variable:** - Old: `RENDERER_BUNDLE_PATH` - New: `RENDERER_SERVER_BUNDLE_CACHE_PATH` Both the old config option and env var will continue to work with deprecation warnings. ## Test plan - [x] ESLint passes - [x] RuboCop passes - [x] All documentation updated - [x] Backwards compatibility maintained 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- Reviewable:start --> - - - This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/shakacode/react_on_rails/2008) <!-- Reviewable:end --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7bdf4eb commit fffa737

File tree

12 files changed

+290
-133
lines changed

12 files changed

+290
-133
lines changed

react_on_rails_pro/CHANGELOG.md

Lines changed: 134 additions & 29 deletions
Large diffs are not rendered by default.

react_on_rails_pro/docs/installation.md

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Installation
2+
23
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.
34

45
Check the [CHANGELOG](https://github.com/shakacode/react_on_rails_pro/blob/master/CHANGELOG.md) to see what version you want.
@@ -8,13 +9,16 @@ Check the [CHANGELOG](https://github.com/shakacode/react_on_rails_pro/blob/maste
89
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`.
910

1011
# Ruby
12+
1113
## Gem Installation
14+
1215
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-
16+
1. Add the `react_on_rails_pro` gem to your **Gemfile**. Substitute the appropriate version number.
17+
1518
## Gemfile Change
1619

1720
Replace the following in the snippet for the Gemfile
21+
1822
1. `<account>` for the api key
1923
2. `<api-key>`
2024
3. `<version>` desired
@@ -33,6 +37,7 @@ source "https://rubygems.pkg.github.com/shakacode-tools" do
3337
gem "react_on_rails_pro", "<version>"
3438
end
3539
```
40+
3641
Or use the `gem install` command:
3742

3843
```bash
@@ -46,30 +51,35 @@ bundle config set rubygems.pkg.github.com <username>:<token>
4651
```
4752
4853
## Using a branch in your Gemfile
54+
4955
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-
```
56+
57+
```ruby
58+
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>"
59+
```
5360
5461
## Rails Configuration
55-
You don't need to create an initializer if you are satisfied with the default as described in
62+
63+
You don't need to create an initializer if you are satisfied with the default as described in
5664
[Configuration](./configuration.md)
5765
5866
# Node Package
67+
5968
Note, you only need to install the Node Package if you are using the standalone node renderer, `NodeRenderer`.
6069
6170
## Installation
6271
6372
1. Create a subdirectory of your rails project for the Node renderer. Let's use `react-on-rails-pro`.
64-
6573
2. Create a file `react-on-rails-pro/.npmrc` with the following
74+
6675
```
6776
always-auth=true
6877
//npm.pkg.github.com/:_authToken=<token>
6978
@shakacode-tools:registry=https://npm.pkg.github.com
7079
```
7180
7281
3. Create a `react-on-rails-pro/package.json`
82+
7383
```json
7484
{
7585
"private": true,
@@ -86,20 +96,18 @@ always-auth=true
8696
8797
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)
8898
89-
5. You can start the renderer with either the executable `node-renderer` or, preferably, with
99+
5. You can start the renderer with either the executable `node-renderer` or, preferably, with
90100
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.
101+
these contents. \_Note the use of the namespaced **`@shakacode-tools/react-on-rails-pro-node-renderer`** for the package.
92102
93103
```js
94-
const path = require('path')
95-
const {
96-
reactOnRailsProNodeRenderer,
97-
} = require('@shakacode-tools/react-on-rails-pro-node-renderer')
104+
const path = require('path');
105+
const { reactOnRailsProNodeRenderer } = require('@shakacode-tools/react-on-rails-pro-node-renderer');
98106
99-
const env = process.env
107+
const env = process.env;
100108
101109
const config = {
102-
bundlePath: path.resolve(__dirname, '../.node-renderer-bundles'),
110+
serverBundleCachePath: path.resolve(__dirname, '../.node-renderer-bundles'),
103111
104112
// Listen at RENDERER_PORT env value or default port 3800
105113
logLevel: env.RENDERER_LOG_LEVEL || 'debug', // show all logs
@@ -132,21 +140,22 @@ const config = {
132140
// Also, you can set he parameter gracefulWorkerRestartTimeout to force the worker to restart
133141
// If it's the time for the worker to restart, the worker waits until it serves all active requests before restarting
134142
// If a worker stuck because of a memory leakage or an infinite loop, you can set a timeout that master waits for it before killing the worker
135-
}
143+
};
136144
137145
// Renderer detects a total number of CPUs on virtual hostings like Heroku
138146
// or CircleCI instead of CPUs number allocated for current container. This
139147
// results in spawning many workers while only 1-2 of them really needed.
140148
if (env.CI) {
141-
config.workersCount = 2
149+
config.workersCount = 2;
142150
}
143151
144-
reactOnRailsProNodeRenderer(config)
152+
reactOnRailsProNodeRenderer(config);
145153
```
146154
147155
## Instructions for using a branch
148156
149157
Install the node-renderer executable, possibly globally. Substitute the branch name or tag for `master`
158+
150159
```
151160
yarn global add https://<your-github-token>:x-oauth-basic@github.com/shakacode/react_on_rails_pro.git\#master
152161
```
@@ -159,28 +168,34 @@ Login into npm
159168
160169
```bash
161170
npm install @shakacode-tools/react-on-rails-pro-node-renderer@<version>
162-
```
171+
```
163172
164173
or edit package.json directly
174+
165175
```json
166176
"@shakacode-tools/react-on-rails-pro-node-renderer": "<version>"
167-
```
177+
```
168178
169179
### Configuration
180+
170181
See [NodeRenderer JavaScript Configuration](./node-renderer/js-configuration.md).
171182
172183
#### Webpack Configuration
184+
173185
Set your server bundle webpack configuration to use a target of `node` per the [Webpack docs](https://webpack.js.org/concepts/targets/#usage).
174186
175187
## Authentication when using Github packages
188+
176189
[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)
177190
178191
Create a new ~/.npmrc file if one doesn't exist.
192+
179193
```
180194
//npm.pkg.github.com/:_authToken=TOKEN
181-
```
195+
```
182196
183197
To configure bundler if you don't want the token in your Gemfile:
198+
184199
```
185200
bundle config https://rubygems.pkg.github.com/OWNER USERNAME:TOKEN
186-
```
201+
```
Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11
# 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.
34

45
# Install the Gem and the Node Module
6+
57
See [Installation](../installation.md).
68

79
# Setup Node Renderer Server
10+
811
**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.
912

1013
## Simple Command Line for node-renderer
1114

1215
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`
2124
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:
2225
```
2326
RENDERER_BUNDLE_PATH=/app/.node-renderer-bundles node-renderer
2427
```
2528
3. You can use a command line argument of `-p SOME_PORT` to override any ENV value for the PORT.
2629

2730
## JavaScript Configuration File
31+
2832
For the most control over the setup, create a JavaScript file to start the NodeRenderer.
2933

3034
1. Create some project directory, let's say `renderer-app`:
@@ -38,48 +42,51 @@ For the most control over the setup, create a JavaScript file to start the NodeR
3842
yarn init
3943
yarn add https://[your-github-token]:x-oauth-basic@github.com/shakacode/react_on_rails_pro.git\#master
4044
```
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:
4246

4347
```javascript
4448
import path from 'path';
4549
import reactOnRailsProNodeRenderer from '@shakacode-tools/react-on-rails-pro-node-renderer';
4650

4751
const config = {
48-
bundlePath: path.resolve(__dirname, '../.node-renderer-bundles'),
52+
serverBundleCachePath: path.resolve(__dirname, '../.node-renderer-bundles'),
4953
};
5054

5155
reactOnRailsProNodeRenderer(config);
5256
```
57+
5358
5. Now you can launch your renderer server with `node node-renderer.js`. You will probably add a script to your `package.json`.
5459
6. You can use a command line argument of `-p SOME_PORT` to override any configured or ENV value for the port.
5560

5661
# Setup Rails Application
62+
5763
Create `config/initializers/react_on_rails_pro.rb` and configure the **renderer server**. See configuration values in [Configuration](../configuration.md). Pay attention to:
5864

5965
1. Set `config.server_renderer = "NodeRenderer"`
6066
2. Leave the default of `config.prerender_caching = true` and ensure your Rails cache is properly configured to handle the additional cache load.
6167
3. Configure values beginning with `renderer_`
6268
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`.
6369
5. Here's a tiny example using mostly defaults:
70+
6471
```ruby
6572
ReactOnRailsPro.configure do |config|
6673
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"]
7077
end
7178
```
7279

7380
## Troublshooting
7481

75-
* See [JS Memory Leaks](../js-memory-leaks.md).
76-
82+
- See [JS Memory Leaks](../js-memory-leaks.md).
83+
7784
## Upgrading
7885

7986
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.
8087

8188
## References
8289

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)

0 commit comments

Comments
 (0)