react_on_rails_pro 16.2.0.beta.19 → 16.2.0.rc.0

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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -1
  3. data/CONTRIBUTING.md +64 -43
  4. data/Gemfile.lock +4 -4
  5. data/README.md +1 -1
  6. data/docs/bundle-caching.md +22 -8
  7. data/docs/caching.md +39 -27
  8. data/docs/code-splitting-loadable-components.md +2 -2
  9. data/docs/code-splitting.md +74 -70
  10. data/docs/configuration.md +6 -6
  11. data/docs/contributors-info/onboarding-customers.md +2 -1
  12. data/docs/contributors-info/releasing.md +1 -0
  13. data/docs/contributors-info/style.md +23 -15
  14. data/docs/home-pro.md +33 -15
  15. data/docs/installation.md +51 -2
  16. data/docs/js-memory-leaks.md +2 -3
  17. data/docs/node-renderer/debugging.md +5 -1
  18. data/docs/node-renderer/error-reporting-and-tracing.md +27 -15
  19. data/docs/node-renderer/heroku.md +4 -5
  20. data/docs/profiling-server-side-rendering-code.md +43 -42
  21. data/docs/react-server-components/add-streaming-and-interactivity.md +1 -1
  22. data/docs/react-server-components/create-without-ssr.md +18 -18
  23. data/docs/react-server-components/glossary.md +22 -3
  24. data/docs/react-server-components/how-react-server-components-work.md +25 -18
  25. data/docs/react-server-components/inside-client-components.md +19 -18
  26. data/docs/react-server-components/purpose-and-benefits.md +24 -14
  27. data/docs/react-server-components/rendering-flow.md +7 -3
  28. data/docs/react-server-components/server-side-rendering.md +23 -22
  29. data/docs/release-notes/4.0.md +103 -94
  30. data/docs/release-notes/v4-react-server-components.md +16 -16
  31. data/docs/streaming-server-rendering.md +2 -4
  32. data/docs/troubleshooting.md +5 -2
  33. data/docs/updating.md +49 -13
  34. data/lib/react_on_rails_pro/request.rb +18 -3
  35. data/lib/react_on_rails_pro/version.rb +1 -1
  36. data/rakelib/dummy_apps.rake +4 -4
  37. data/rakelib/lint.rake +1 -1
  38. data/rakelib/run_rspec.rake +3 -3
  39. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0948b2364bf24887f838e2f27fc5ed8b1d8b79bc353501d9d13b05bc1678ad24'
4
- data.tar.gz: f15f10243f24c7f66211d9cf281428be7657aab395b862110e4ce4b303eaecfd
3
+ metadata.gz: 8a646e0fc2f72d012e57cf12d2f3439e226ac56e176705a2934ef824b29d4236
4
+ data.tar.gz: cfe6963cd813e7a885e30a11fb2d8f2b28adb3a4943ebcc6ddebd140f72042e9
5
5
  SHA512:
6
- metadata.gz: 15850fdf3f3d8b756f213e864ab0d245c7d941fa18d6eae9005cc4f49b8007e73e409a2a748d0e422ddcea504a741cc9d6191dc5d17652736b4ce91b15f5f1dd
7
- data.tar.gz: 250fb9336012cd4ece659212cd076503d30d7959f148581d16fa26ed32eb09e584dab20272614d44b27afbcd15c489656dbd5289fea969045c4197e66d488aa9
6
+ metadata.gz: 23900984ebb5758264088d9bcfa0c05341ce1b586702927f715aaa6b98794545df1b2ff1de92b548b5f16a8cbdc622dea8b8816c7c47269f0c161a302339e17f
7
+ data.tar.gz: 351b76344a8ea9477ac553249407678e71ab535ae1687df3c1318528042902f72cca662c16ecbd749ce1948ad13dc3710502bd1f8a9bce78a1ff678aa5de2d5b
data/CHANGELOG.md CHANGED
@@ -50,6 +50,8 @@ Changes since the last non-beta release.
50
50
 
51
51
  ### Fixed
52
52
 
53
+ - **Thread-Safe Connection Management**: Fixed race conditions in `ReactOnRailsPro::Request` connection management. The lazy initialization (`@connection ||= create_connection`) was not atomic, allowing multiple threads to create duplicate connections at startup. Now uses a mutex with double-checked locking pattern for thread-safe initialization while maintaining lock-free reads for optimal performance. [PR 2259](https://github.com/shakacode/react_on_rails/pull/2259) by [AbanoubGhadban](https://github.com/AbanoubGhadban).
54
+
53
55
  - **SECURITY: CVE-2025-55182 - React Server Components RCE Vulnerability**: by updating `react-on-rails-rsc` peer dependency to `v19.0.3` which mitigates that vulnerability. Also, users should update `react` and `react-dom` package versions to `v19.0.1` to ensure complete mitigation. [PR 2175](https://github.com/shakacode/react_on_rails/pull/2175) by [AbanoubGhadban](https://github.com/AbanoubGhadban).
54
56
 
55
57
  - Fixed compatibility issue with httpx 1.6.x by explicitly requiring http-2 >= 1.1.1. [PR 2141](https://github.com/shakacode/react_on_rails/pull/2141) by [AbanoubGhadban](https://github.com/AbanoubGhadban).
@@ -102,7 +104,7 @@ Changes since the last non-beta release.
102
104
  - Seamlessly use React Server Components in your Rails apps
103
105
  - Reduce client bundle sizes
104
106
  - Enable powerful new patterns for data fetching
105
- - [See the full tutorial](https://www.shakacode.com/react-on-rails-pro/docs/react-server-components-tutorial)
107
+ - [See the full tutorial](https://www.shakacode.com/react-on-rails-pro/docs/react-server-components/tutorial)
106
108
 
107
109
  [PR 422](https://github.com/shakacode/react_on_rails_pro/pull/422) by [AbanoubGhadban](https://github.com/AbanoubGhadban).
108
110
 
data/CONTRIBUTING.md CHANGED
@@ -4,34 +4,36 @@
4
4
 
5
5
  Install [yalc](https://github.com/wclr/yalc).
6
6
 
7
-
8
7
  ```sh
8
+ pnpm install -r
9
9
  cd react_on_rails_pro
10
- bundle && yarn && cd spec/dummy && bundle && yarn
10
+ bundle && cd spec/dummy && bundle && pnpm install
11
11
  ```
12
+
12
13
  To use the `React 18 Apollo with GraphQL` example you need to seed the testing database inside `spec/dummy` directory.
14
+
13
15
  ```sh
14
16
  rake db:seed
15
17
  ```
16
18
 
17
-
18
19
  See the example apps under `/spec`
19
20
 
20
21
  ## Summary
21
22
 
22
23
  For non-doc fixes:
23
24
 
24
- * Provide changelog entry in the [unreleased section of the CHANGELOG.md](https://github.com/shakacode/react_on_rails_pro/blob/master/CHANGELOG.md#unreleased).
25
- * Ensure CI passes and that you added a test that passes with the fix and fails without the fix.
26
- * Squash all commits down to one with a nice commit message *ONLY* once final review is given. Make sure this single commit is rebased on top of master.
27
- * Please address all code review comments.
28
- * Ensure that docs are updated accordingly if a feature is added.
25
+ - Provide changelog entry in the [unreleased section of the CHANGELOG.md](https://github.com/shakacode/react_on_rails_pro/blob/master/CHANGELOG.md#unreleased).
26
+ - Ensure CI passes and that you added a test that passes with the fix and fails without the fix.
27
+ - Squash all commits down to one with a nice commit message _ONLY_ once final review is given. Make sure this single commit is rebased on top of master.
28
+ - Please address all code review comments.
29
+ - Ensure that docs are updated accordingly if a feature is added.
29
30
 
30
31
  ## Commit Messages
31
32
 
32
33
  From [How to Write a Git Commit Message](http://chris.beams.io/posts/git-commit/)
33
34
 
34
- #### The seven rules of a great git commit message
35
+ ### The seven rules of a great git commit message
36
+
35
37
  > Keep in mind: This has all been said before.
36
38
 
37
39
  1. Separate subject from body with a blank line
@@ -42,21 +44,21 @@ From [How to Write a Git Commit Message](http://chris.beams.io/posts/git-commit/
42
44
  1. Wrap the body at 72 characters
43
45
  1. Use the body to explain what and why vs. how
44
46
 
45
-
46
47
  ## Doc Changes
47
48
 
48
- When making doc changes, we want the change to work on both https://www.shakacode.com/react-on-rails-pro/docs/ and when browsing the GitHub repo.
49
+ When making doc changes, we want the change to work on both [the ShakaCode docs site](https://www.shakacode.com/react-on-rails-pro/docs/) and when browsing the GitHub repo.
49
50
  The issue is that the Shakacode site is generated only from files in [`docs`](./docs), so any references from them to non-doc files must use the full GitHub URL.
50
51
 
51
52
  ### Links to other docs:
52
- * When making references to doc files, use a relative URL path like:
53
- `[Installation Overview](docs/basics/installation-overview.md)`
54
53
 
55
- * When making references to source code files, use a full url path like:
56
- `[spec/dummy/config/initializers/react_on_rails.rb](https://github.com/shakacode/react_on_rails_pro/tree/master/spec/dummy/config/initializers/react_on_rails.rb)`
54
+ - When making references to doc files, use a relative URL path like:
55
+ `[Installation Overview](docs/basics/installation-overview.md)`
57
56
 
57
+ - When making references to source code files, use a full url path like:
58
+ `[spec/dummy/config/initializers/react_on_rails.rb](https://github.com/shakacode/react_on_rails_pro/tree/master/spec/dummy/config/initializers/react_on_rails.rb)`
58
59
 
59
60
  ## To run tests:
61
+
60
62
  See [Run NPM JS tests](#run-npm-js-tests) for the JS tests and [RSpec Testing](#rspec-testing) for the Ruby tests.
61
63
 
62
64
  See [Dev Initial Setup](#dev-initial-setup) below for, well... initial setup.
@@ -107,30 +109,33 @@ script/ci-changes-detector origin/master
107
109
  ### CI Best Practices for Pro
108
110
 
109
111
  ✅ **DO:**
112
+
110
113
  - Run `bin/ci-local` from repository root before pushing
111
114
  - Test Pro changes alongside main gem changes if modifying both
112
115
  - Use `bin/ci-local --fast` during rapid iteration
113
116
 
114
117
  ❌ **DON'T:**
118
+
115
119
  - Push Pro changes without testing locally first
116
120
  - Modify both Pro and main gem without running full tests
117
121
 
118
122
  For comprehensive CI documentation, see [`../docs/CI_OPTIMIZATION.md`](../docs/CI_OPTIMIZATION.md) in the repository root.
119
123
 
120
124
  # IDE/Editor Setup
121
- It's critical to configure your IDE/editor to ignore certain directories. Otherwise your IDE might slow to a crawl!
122
125
 
123
- * /coverage
124
- * /tmp
125
- * /node_modules
126
- * /spec/dummy/app/assets/webpack
127
- * /spec/dummy/log
128
- * /spec/dummy/node_modules
129
- * /spec/dummy/client/node_modules
130
- * /spec/dummy/tmp
126
+ It's critical to configure your IDE/editor to ignore certain directories. Otherwise your IDE might slow to a crawl!
131
127
 
128
+ - /coverage
129
+ - /tmp
130
+ - /node_modules
131
+ - /spec/dummy/app/assets/webpack
132
+ - /spec/dummy/log
133
+ - /spec/dummy/node_modules
134
+ - /spec/dummy/client/node_modules
135
+ - /spec/dummy/tmp
132
136
 
133
137
  # Configuring your test app to use your local fork
138
+
134
139
  You can test the `react_on_rails_pro` 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.
135
140
  As of 2018-04-28, this directory mirrors the test app spec/dummy on https://github.com/shakacode/react_on_rails plus a few additional tests.
136
141
 
@@ -143,15 +148,17 @@ As of 2018-04-28, this directory mirrors the test app spec/dummy on https://gith
143
148
  ```
144
149
 
145
150
  ## Testing the Ruby Gem
151
+
146
152
  If you want to test the ruby parts of the gem with an application before you release a new version of the gem, you can specify the path to your local version via your test app's Gemfile:
147
153
 
148
154
  ```ruby
149
155
  gem "react_on_rails_pro", path: "../path-to-react_on_rails_pro"
150
156
  gem "react_on_rails"
151
157
  ```
158
+
152
159
  ================================================================================
153
160
 
154
- Set `config.server_renderer = "NodeRenderer"` in your `ReactOnRailsPro.configure` block in the initializer.
161
+ Set `config.server_renderer = "NodeRenderer"` in your `ReactOnRailsPro.configure` block in the initializer.
155
162
 
156
163
  After making this change, run `bundle install`.
157
164
 
@@ -159,6 +166,7 @@ After making this change, run `bundle install`.
159
166
  > You will need to restart your Rails application if you make any changes to the gem.
160
167
 
161
168
  ## Testing the Node package for react_on_rails_pro
169
+
162
170
  In addition to testing the Ruby parts out, you can also test the node package parts of the gem with an external application.
163
171
 
164
172
  To do this, follow the instructions in the
@@ -166,19 +174,21 @@ To do this, follow the instructions in the
166
174
 
167
175
  ### Example: Testing NPM changes with the dummy app
168
176
 
169
- 1. Add `console.log('Hello!')` [here](https://github.com/shakacode/react_on_rails_pro/blob/more_test_and_docs/packages/node-renderer/src/ReactOnRailsProNodeRenderer.js#L6) in `packages/node-renderer/src/ReactOnRailsProNodeRenderer.js` to confirm we're getting an update to the node package.
170
- 2. The `preinstall` script of `spec/dummy` builds the NPM package and sets up `yalc` to use it for the renderer.
171
- It's run automatically when you run `yarn install`.
177
+ 1. Add `console.log('Hello!')` [here](https://github.com/shakacode/react_on_rails_pro/blob/master/packages/node-renderer/src/ReactOnRailsProNodeRenderer.ts#L6) in `packages/node-renderer/src/ReactOnRailsProNodeRenderer.ts` to confirm we're getting an update to the node package.
178
+ 2. The `preinstall` script of `spec/dummy` builds the NPM package and sets up `yalc` to use it for the renderer.
179
+ It's run automatically when you run `pnpm install`.
172
180
  3. Refresh the browser if the server is already running or start the server using `foreman start -f Procfile.dev` from `spec/dummy` and navigate to `http://localhost:3000/`. You will now see the `Hello!` message printed in the browser's console.
173
181
 
182
+ <!-- prettier-ignore -->
174
183
  > [!NOTE]
175
184
  > `yalc` makes the NPM package available globally on the machine.
176
185
  > So, if you have the repo checked out more than once to compare behavior between branches,
177
- > make sure to run `yarn install` every time you switch to a new copy.
186
+ > make sure to run `pnpm install` every time you switch to a new copy.
178
187
 
179
188
  # Development Setup for Gem and Node Package Contributors
180
189
 
181
190
  ## Checklist before Committing
191
+
182
192
  1. Run all JS tests, dummy app tests and linters.
183
193
  2. Did you need any more tests for your change?
184
194
  3. Did you document your change? Update the README.md?
@@ -186,12 +196,13 @@ To do this, follow the instructions in the
186
196
  ## Dev Initial Setup
187
197
 
188
198
  ### Prereqs
189
- After checking out the repo, making sure you have rvm and nvm setup (setup ruby and node), cd to `spec/dummy` and run `bin/setup` to install ruby dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
190
199
 
200
+ After checking out the repo, making sure you have rvm and nvm setup (setup ruby and node), cd to `spec/dummy` and run `bin/setup` to install ruby dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
191
201
 
192
202
  ### Building the Node Package for Development
193
203
 
194
204
  At the root:
205
+
195
206
  ```
196
207
  nps build
197
208
  ```
@@ -207,6 +218,7 @@ This is a possible update to package.json to debug the lockfile. Notice the `NOD
207
218
  See https://nodejs.org/api/util.html#util_util_debuglog_section for details on `debuglog`.
208
219
 
209
220
  ### Local Node Package
221
+
210
222
  Because the example and dummy apps rely on the `react_on_rails_pro` node package, they should link directly to your local version to pick up any changes you may have made to that package.
211
223
  To achieve this, you can use `yalc`.
212
224
  The easy way to do this is to run the command below in the dummy app root directory.
@@ -215,11 +227,11 @@ For more information check the script section of the
215
227
 
216
228
  ```sh
217
229
  cd spec/dummy
218
- yarn install
230
+ pnpm install -r
219
231
  ```
220
232
 
221
233
  > [!NOTE]
222
- > This runs npm under the hood as explained in the **Test NPM for react_on_rails_pro** section above.
234
+ > This uses yalc under the hood as explained in the **Example: Testing NPM changes with the dummy app** section above.
223
235
 
224
236
  From now on, the example and dummy apps will use your local packages/node-renderer folder as the `react_on_rails_pro` node package.
225
237
 
@@ -227,51 +239,55 @@ From now on, the example and dummy apps will use your local packages/node-render
227
239
 
228
240
  ```sh
229
241
  cd react_on_rails_pro
230
- yarn install
242
+ pnpm install -r
231
243
  ```
232
244
 
233
- Or run this, which builds the yarn package, then the webpack files for spec/dummy, and finally runs tests in
245
+ Or run this, which builds the pnpm package, then the webpack files for spec/dummy, and finally runs tests in
234
246
  spec/dummy.
235
247
 
236
-
237
248
  ```sh
238
249
  # Optionally change default selenium_firefox driver
239
250
  # export DRIVER=poltergeist
240
251
  cd react_on_rails_pro
241
- yarn run dummy:spec
252
+ pnpm run dummy:spec
242
253
  ```
243
254
 
244
255
  ### Run NPM JS tests
245
256
 
246
257
  ```sh
247
258
  cd react_on_rails_pro
248
- yarn test
259
+ pnpm test
249
260
  ```
250
261
 
251
262
  ### Debugging NPM JS tests
252
263
 
253
264
  Example of using ndb to debug a test
265
+
254
266
  ```bash
255
- ndb $(yarn bin)/jest --runInBand packages/node-renderer/tests/**/*.test.[jt]s -t 'FriendsAndGuests bundle for commit 1a7fe417'
267
+ ndb $(pnpm bin)/jest --runInBand packages/node-renderer/tests/**/*.test.[jt]s -t 'FriendsAndGuests bundle for commit 1a7fe417'
256
268
  ```
269
+
257
270
  Hit F8 and then a debugger statement within the test will get hit.
258
271
 
259
272
  ### Creating new VM tests
273
+
260
274
  1. copy a server bundle to `packages/node-renderer/tests/fixtures/projects/<project-name>/<commit>`
261
275
  2. create a directory with a hash representing the commit of the project
262
276
 
263
277
  ### Async issues with Jest
278
+
264
279
  Beware that Jest runs multiple test files synchronously, so you can't use the same temporary directory
265
- between tests. See the file [`packages/node-renderer/tests/helper.ts`](packages/node-renderer/tests/helper.ts) for how we handle this.
280
+ between tests. See the file [`packages/node-renderer/tests/helper.ts`](https://github.com/shakacode/react_on_rails_pro/blob/master/packages/node-renderer/tests/helper.ts) for how we handle this.
266
281
 
267
282
  ### Run most tests and linting
268
283
 
269
284
  ```sh
270
285
  cd react_on_rails_pro
271
- yarn run check
286
+ pnpm run check
272
287
  ```
273
288
 
274
289
  ### Starting the Dummy App
290
+
275
291
  Before running the dummy app,
276
292
  you need to generate JavaScript packs in the dummy app project.
277
293
  To do this,
@@ -298,15 +314,17 @@ Before running Ruby tests ensure you have done the following steps in `spec/dumm
298
314
 
299
315
  ```sh
300
316
  # in the root directory
317
+ pnpm install -r
318
+
319
+ cd react_on_rails
301
320
  bundle install
302
- yarn install
303
321
 
304
322
  cd spec/dummy
305
323
 
306
324
  bundle install
307
325
  bundle exec rake react_on_rails:generate_packs
308
326
 
309
- yarn install
327
+ pnpm install -r
310
328
 
311
329
  RAILS_ENV=test bin/shakapacker # to generate assets for test environment
312
330
  ```
@@ -315,7 +333,7 @@ Then in a separate terminal, run the following to run the Node renderer and the
315
333
 
316
334
  ```sh
317
335
  # in spec/dummy directory
318
- yarn run node-renderer
336
+ pnpm run node-renderer
319
337
  RAILS_ENV=test bin/dev&
320
338
  ```
321
339
 
@@ -330,6 +348,7 @@ If you run `rspec` at the top level, you'll see this message: `require': cannot
330
348
  After running a test, you can view the coverage results in SimpleCov reports by opening `coverage/index.html`.
331
349
 
332
350
  ### Debugging
351
+
333
352
  Start the sample app like this for some debug printing:
334
353
 
335
354
  ```sh
@@ -350,6 +369,7 @@ Contact Justin Gordon, [justin@shakacode.com](mailto:justin@shakacode.com) for r
350
369
  You need authentication for public package registries:
351
370
 
352
371
  **Public packages (npmjs.org + rubygems.org):**
372
+
353
373
  - NPM: Run `npm login`
354
374
  - RubyGems: Standard credentials via `gem push`
355
375
 
@@ -372,5 +392,6 @@ rake release[17.0.0,false,verdaccio]
372
392
  ```
373
393
 
374
394
  For complete documentation, see:
395
+
375
396
  - [Root Release Documentation](../docs/contributor-info/releasing.md)
376
397
  - Run `rake -D release` for inline help
data/Gemfile.lock CHANGED
@@ -9,7 +9,7 @@ GIT
9
9
  PATH
10
10
  remote: ..
11
11
  specs:
12
- react_on_rails (16.2.0.beta.19)
12
+ react_on_rails (16.2.0.rc.0)
13
13
  addressable
14
14
  connection_pool
15
15
  execjs (~> 2.5)
@@ -20,7 +20,7 @@ PATH
20
20
  PATH
21
21
  remote: .
22
22
  specs:
23
- react_on_rails_pro (16.2.0.beta.19)
23
+ react_on_rails_pro (16.2.0.rc.0)
24
24
  addressable
25
25
  async (>= 2.6)
26
26
  connection_pool
@@ -29,7 +29,7 @@ PATH
29
29
  httpx (~> 1.5)
30
30
  jwt (~> 2.7)
31
31
  rainbow
32
- react_on_rails (= 16.2.0.beta.19)
32
+ react_on_rails (= 16.2.0.rc.0)
33
33
 
34
34
  GEM
35
35
  remote: https://rubygems.org/
@@ -336,7 +336,7 @@ GEM
336
336
  regexp_parser (2.9.2)
337
337
  reline (0.6.3)
338
338
  io-console (~> 0.5)
339
- rexml (3.3.9)
339
+ rexml (3.4.4)
340
340
  rspec-core (3.13.0)
341
341
  rspec-support (~> 3.13.0)
342
342
  rspec-expectations (3.13.1)
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![License](https://img.shields.io/badge/license-Commercial-blue.svg)](./LICENSE)
4
4
  [![Build Integration Tests](https://github.com/shakacode/react_on_rails/actions/workflows/pro-integration-tests.yml/badge.svg)](https://github.com/shakacode/react_on_rails/actions/workflows/pro-integration-tests.yml)
5
5
  [![Build Lint](https://github.com/shakacode/react_on_rails/actions/workflows/pro-lint.yml/badge.svg)](https://github.com/shakacode/react_on_rails/actions/workflows/pro-lint.yml)
6
- [![Build Package Tests](https://github.com/shakacode/react_on_rails/actions/workflows/pro-package-tests.yml/badge.svg)](https://github.com/shakacode/react_on_rails/actions/workflows/pro-package-tests.yml)
6
+ [![Build Package Tests](https://github.com/shakacode/react_on_rails/actions/workflows/pro-test-package-and-gem.yml/badge.svg)](https://github.com/shakacode/react_on_rails/actions/workflows/pro-test-package-and-gem.yml)
7
7
 
8
8
  **Performance enhancements and advanced features for [React on Rails](https://github.com/shakacode/react_on_rails).**
9
9
 
@@ -1,16 +1,19 @@
1
1
  # Bundle Caching
2
2
 
3
3
  ## Why?
4
+
4
5
  Building webpack bundles is often time-consuming, and the same bundles are built many times.
5
6
  For example, you might build the production bundles during CI, then for a Review app, then
6
- for Staging, and maybe even for Production. Or you might want to deploy a small Ruby only
7
+ for Staging, and maybe even for Production. Or you might want to deploy a small Ruby-only
7
8
  change to production, but you will have to wait minutes for your bundles to be built again.
8
9
 
9
10
  ## Solution
11
+
10
12
  React on Rails 2.1.0 introduces bundle caching based on a digest of all the source files, defined
11
13
  in the `config/shakapacker.yml` file, plus other files defined with `config.dependency_globs` and
12
14
  excluding any files from `config.excluded_dependency_globs`. Creating this hash key takes at most a
13
- few seconds for even large projects. Additionally, the cache key includes
15
+ few seconds for even large projects. Additionally, the cache key includes
16
+
14
17
  1. NODE_ENV
15
18
  2. Version of React on Rails Pro
16
19
  3. Configurable additional env values by supplying an array in method cache_keys on the `remote_bundle_cache_adapter`. See examples below.
@@ -18,6 +21,7 @@ few seconds for even large projects. Additionally, the cache key includes
18
21
  This cache key is used for saving files to some remote storage, typically S3.
19
22
 
20
23
  ## Bonus for local development with multiple directories building production builds
24
+
21
25
  Bundle caching can help save time if you have multiple directories for the same repository.
22
26
 
23
27
  The bundles are cached in `Rails.root.join('tmp', 'bundle_cache')`
@@ -32,6 +36,7 @@ ln -s ../../my_project/tmp/bundle_cache
32
36
  ## Configuration
33
37
 
34
38
  ### 1. React on Rails Configuration
39
+
35
40
  First, we need to tell React on Rails to use a custom build module. In
36
41
  `config/initializers/react_on_rails`, set this value:
37
42
 
@@ -49,7 +54,7 @@ ReactOnRails.configure do |config|
49
54
  end
50
55
  ```
51
56
 
52
- And define it like this:
57
+ And define it like this:
53
58
 
54
59
  ```ruby
55
60
  module CustomBuildCommand
@@ -61,6 +66,7 @@ end
61
66
  ```
62
67
 
63
68
  ### 2. React on Rails Pro Configuration
69
+
64
70
  Next, we need to configure the `config/initializers/react_on_rails_pro.rb` with some module,
65
71
  say called S3BundleCacheAdapter.
66
72
 
@@ -79,21 +85,26 @@ cached_react_component and cached_react_component_hash, add those as well to `co
79
85
  To simplify your configuration, entire directories can be added to `config.dependency_globs` & then any irrelevant files or subdirectories can be added to `config.excluded_dependency_globs`
80
86
 
81
87
  For example:
88
+
82
89
  ```ruby
83
90
  config.dependency_globs = [ File.join(Rails.root, "app", "views", "**", "*.jbuilder") ]
84
91
  config.excluded_dependency_globs = [ File.join(Rails.root, "app", "views", "**", "dont_hash_this.jbuilder") ]
85
92
  ```
93
+
86
94
  will hash all files in `app/views` that have the `jbuilder` extension except for any file named `dont_hash_this.jbuilder`.
87
95
 
88
96
  The goal is that Ruby only changes that don't affect your webpack bundles don't change the cache keys, and anything that could affect the bundles MUST change the cache keys!
89
97
 
90
98
  ### 3. Remove any call to rake task `react_on_rails_pro:pre_stage_bundle_for_node_renderer`
91
- This task is called automaticaly if you're using bundle caching.
99
+
100
+ This task is called automatically if you're using bundle caching.
101
+
92
102
  ```ruby
93
103
  Rake::Task['react_on_rails_pro:pre_stage_bundle_for_node_renderer'].invoke
94
104
  ```
95
105
 
96
106
  #### Custom ENV cache keys
107
+
97
108
  Check your webpack config for the webpack.DefinePlugin. That allows JS code to use
98
109
  `process.env.MY_ENV_VAR` resulting in bundles that differ depending on the ENV value set.
99
110
 
@@ -115,12 +126,14 @@ Another use of the ENV values would be a cache version, so incrementing this ENV
115
126
  would force a new cache value.
116
127
 
117
128
  ## Disabling via an ENV value
129
+
118
130
  Once configured for bundle caching, ReactOnRailsPro::AssetsPrecompile's caching functionality
119
131
  can be disabled by setting ENV["DISABLE_PRECOMPILE_CACHE"] equal to "true"
120
132
 
121
133
  ### Examples of `remote_bundle_cache_adapter`:
122
134
 
123
135
  #### S3BundleCacheAdapter
136
+
124
137
  Example of a module for custom methods for the `remote_bundle_cache_adapter`.
125
138
 
126
139
  Note, S3UploadService is your own code that fetches and uploads.
@@ -140,7 +153,7 @@ class S3BundleCacheAdapter
140
153
  def self.cache_keys
141
154
  [Rails.env, ENV['SOME_ENV_VALUE']]
142
155
  end
143
-
156
+
144
157
  # return value is unused
145
158
  # This command should build the bundles
146
159
  def self.build
@@ -153,8 +166,8 @@ class S3BundleCacheAdapter
153
166
  result = S3UploadService.new.fetch_object(zipped_bundles_filename)
154
167
  result.get.body.read if result
155
168
  end
156
-
157
- # Optional: method to return an array of extra files paths, that require caching.
169
+
170
+ # Optional: method to return an array of extra files paths, that require caching.
158
171
  # These files get placed at the `extra_files` directory at the top of the zipfile
159
172
  # and are moved to the original places after unzipping the bundles.
160
173
  def self.extra_files_to_cache
@@ -180,6 +193,7 @@ end
180
193
  ```
181
194
 
182
195
  #### LocalBundleCacheAdapter
196
+
183
197
  Example of a module for custom methods for the `remote_bundle_cache_adapter` that does not save files
184
198
  remotely. Only local files are used.
185
199
 
@@ -189,7 +203,7 @@ class LocalBundleCacheAdapter
189
203
  # if no additional cache keys, return an empty array
190
204
  []
191
205
  end
192
-
206
+
193
207
  def self.build
194
208
  Rake.sh(ReactOnRails::Utils.prepend_cd_node_modules_directory('yarn start build.prod').to_s)
195
209
  end