react_on_rails 16.1.2 β†’ 16.2.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 (106) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -0
  3. data/.rubocop.yml +85 -0
  4. data/Gemfile.development_dependencies +8 -7
  5. data/Gemfile.lock +158 -119
  6. data/Steepfile +56 -0
  7. data/lib/generators/react_on_rails/base_generator.rb +43 -120
  8. data/lib/generators/react_on_rails/dev_tests_generator.rb +2 -1
  9. data/lib/generators/react_on_rails/generator_helper.rb +102 -2
  10. data/lib/generators/react_on_rails/install_generator.rb +36 -156
  11. data/lib/generators/react_on_rails/js_dependency_manager.rb +383 -0
  12. data/lib/generators/react_on_rails/templates/base/base/.dev-services.yml.example +76 -0
  13. data/lib/generators/react_on_rails/templates/base/base/bin/shakapacker-precompile-hook +30 -0
  14. data/lib/generators/react_on_rails/templates/base/base/bin/switch-bundler +141 -0
  15. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb.tt +44 -45
  16. data/lib/generators/react_on_rails/templates/base/base/config/{shakapacker.yml β†’ shakapacker.yml.tt} +28 -3
  17. data/lib/generators/react_on_rails/templates/base/base/config/webpack/development.js.tt +15 -9
  18. data/lib/generators/react_on_rails/templates/base/base/config/webpack/serverWebpackConfig.js.tt +42 -6
  19. data/lib/react_on_rails/configuration.rb +149 -32
  20. data/lib/react_on_rails/controller.rb +3 -3
  21. data/lib/react_on_rails/dev/pack_generator.rb +168 -2
  22. data/lib/react_on_rails/dev/process_manager.rb +136 -14
  23. data/lib/react_on_rails/dev/server_manager.rb +194 -26
  24. data/lib/react_on_rails/dev/service_checker.rb +200 -0
  25. data/lib/react_on_rails/doctor.rb +341 -12
  26. data/lib/react_on_rails/engine.rb +75 -1
  27. data/lib/react_on_rails/git_utils.rb +3 -1
  28. data/lib/react_on_rails/helper.rb +70 -192
  29. data/lib/react_on_rails/locales/base.rb +17 -5
  30. data/lib/react_on_rails/packer_utils.rb +79 -2
  31. data/lib/react_on_rails/packs_generator.rb +57 -39
  32. data/lib/react_on_rails/prerender_error.rb +74 -17
  33. data/lib/react_on_rails/pro_helper.rb +64 -0
  34. data/lib/react_on_rails/react_component/render_options.rb +7 -7
  35. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +2 -5
  36. data/lib/react_on_rails/smart_error.rb +326 -0
  37. data/lib/react_on_rails/system_checker.rb +8 -9
  38. data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +16 -7
  39. data/lib/react_on_rails/utils.rb +241 -55
  40. data/lib/react_on_rails/version.rb +1 -1
  41. data/lib/react_on_rails/version_checker.rb +383 -35
  42. data/lib/tasks/generate_packs.rake +12 -6
  43. data/lib/tasks/locale.rake +6 -1
  44. data/rakelib/docker.rake +26 -0
  45. data/rakelib/dummy_apps.rake +30 -0
  46. data/rakelib/example_type.rb +121 -0
  47. data/rakelib/examples_config.yml +52 -0
  48. data/rakelib/lint.rake +52 -0
  49. data/rakelib/node_package.rake +15 -0
  50. data/rakelib/rbs.rake +70 -0
  51. data/rakelib/run_rspec.rake +223 -0
  52. data/rakelib/shakapacker_examples.rake +171 -0
  53. data/rakelib/task_helpers.rb +134 -0
  54. data/rakelib/update_changelog.rake +73 -0
  55. data/react_on_rails.gemspec +4 -3
  56. data/sig/README.md +52 -0
  57. data/sig/react_on_rails/configuration.rbs +96 -0
  58. data/sig/react_on_rails/controller.rbs +15 -0
  59. data/sig/react_on_rails/dev/file_manager.rbs +15 -0
  60. data/sig/react_on_rails/dev/pack_generator.rbs +19 -0
  61. data/sig/react_on_rails/dev/process_manager.rbs +22 -0
  62. data/sig/react_on_rails/dev/server_manager.rbs +39 -0
  63. data/sig/react_on_rails/dev/service_checker.rbs +22 -0
  64. data/sig/react_on_rails/error.rbs +4 -0
  65. data/sig/react_on_rails/generators/js_dependency_manager.rbs +123 -0
  66. data/sig/react_on_rails/git_utils.rbs +8 -0
  67. data/sig/react_on_rails/helper.rbs +65 -0
  68. data/sig/react_on_rails/json_parse_error.rbs +10 -0
  69. data/sig/react_on_rails/locales.rbs +46 -0
  70. data/sig/react_on_rails/packer_utils.rbs +15 -0
  71. data/sig/react_on_rails/prerender_error.rbs +21 -0
  72. data/sig/react_on_rails/server_rendering_pool.rbs +12 -0
  73. data/sig/react_on_rails/smart_error.rbs +28 -0
  74. data/sig/react_on_rails/test_helper.rbs +11 -0
  75. data/sig/react_on_rails/utils.rbs +34 -0
  76. data/sig/react_on_rails/version_checker.rbs +12 -0
  77. data/sig/react_on_rails.rbs +17 -0
  78. metadata +49 -32
  79. data/AI_AGENT_INSTRUCTIONS.md +0 -63
  80. data/CHANGELOG.md +0 -1836
  81. data/CLAUDE.md +0 -135
  82. data/CODING_AGENTS.md +0 -313
  83. data/CONTRIBUTING.md +0 -668
  84. data/Dockerfile_tests +0 -12
  85. data/KUDOS.md +0 -114
  86. data/LICENSE.md +0 -47
  87. data/LICENSES/README.md +0 -14
  88. data/NEWS.md +0 -62
  89. data/PROJECTS.md +0 -63
  90. data/REACT-ON-RAILS-PRO-LICENSE.md +0 -129
  91. data/README.md +0 -217
  92. data/SUMMARY.md +0 -88
  93. data/TODO.md +0 -135
  94. data/bin/lefthook/check-trailing-newlines +0 -38
  95. data/bin/lefthook/get-changed-files +0 -26
  96. data/bin/lefthook/prettier-format +0 -26
  97. data/bin/lefthook/ruby-autofix +0 -26
  98. data/bin/lefthook/ruby-lint +0 -27
  99. data/docker-compose.yml +0 -11
  100. data/eslint.config.ts +0 -232
  101. data/knip.ts +0 -114
  102. data/lib/react_on_rails/pro/NOTICE +0 -21
  103. data/lib/react_on_rails/pro/helper.rb +0 -122
  104. data/lib/react_on_rails/pro/utils.rb +0 -53
  105. data/tsconfig.eslint.json +0 -6
  106. data/tsconfig.json +0 -19
data/CONTRIBUTING.md DELETED
@@ -1,668 +0,0 @@
1
- # Tips for Contributors
2
-
3
- **πŸ—οΈ Important: Monorepo Merger in Progress**
4
-
5
- We are currently working on merging the `react_on_rails` and `react_on_rails_pro` repositories into a unified monorepo. This will provide better development experience while maintaining separate package identities and licensing. See [docs/MONOREPO_MERGER_PLAN_REF.md](./docs/MONOREPO_MERGER_PLAN_REF.md) for details.
6
-
7
- During this transition:
8
-
9
- - Continue contributing to the current structure
10
- - License compliance remains critical - ensure no Pro code enters MIT-licensed areas
11
- - Major structural changes may be coordinated with the merger plan
12
-
13
- ---
14
-
15
- - [docs/contributor-info/Releasing](./docs/contributor-info/releasing.md) for instructions on releasing.
16
- - [docs/contributor-info/pull-requests](./docs/contributor-info/pull-requests.md)
17
- - See other docs in [docs/contributor-info](./docs/contributor-info)
18
-
19
- ## Prerequisites
20
-
21
- - [Yalc](https://github.com/whitecolor/yalc) must be installed globally for most local development.
22
- - **Git hooks setup** (automatic during normal setup):
23
-
24
- Git hooks are installed automatically when you run the standard setup commands. They will run automatic linting on **all changed files (staged + unstaged + untracked)** - making commits fast while preventing CI failures.
25
-
26
- - After updating code via Git, to prepare all examples:
27
-
28
- ```sh
29
- cd react_on_rails/
30
- bundle && yarn && rake shakapacker_examples:gen_all && rake node_package && rake
31
- ```
32
-
33
- See [Dev Initial Setup](#dev-initial-setup) below for, well... initial setup,
34
- and [Running tests](#running-tests) for more details on running tests.
35
-
36
- # IDE/IDE SETUP
37
-
38
- It's critical to configure your IDE/editor to ignore certain directories. Otherwise, your IDE might slow to a crawl!
39
-
40
- - /coverage
41
- - /tmp
42
- - /gen-examples
43
- - /node_package/lib
44
- - /node_modules
45
- - /spec/dummy/app/assets/webpack
46
- - /spec/dummy/log
47
- - /spec/dummy/node_modules
48
- - /spec/dummy/client/node_modules
49
- - /spec/dummy/tmp
50
- - /spec/react_on_rails/dummy-for-generators
51
-
52
- # Configuring your test app to use your local fork
53
-
54
- You can test the `react-on-rails` gem using your own external test app or the gem's internal `spec/dummy` app. The `spec/dummy` app is an example of the various setup techniques you can use with the gem.
55
-
56
- ```text
57
- β”œβ”€β”€ test_app
58
- | └── client
59
- └── react_on_rails
60
- └── spec
61
- └── dummy
62
- ```
63
-
64
- ## Testing the Ruby Gem
65
-
66
- 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:
67
-
68
- ```ruby
69
- gem "react_on_rails", path: "../path-to-react-on-rails"
70
- ```
71
-
72
- Note that you will need to bundle install after making this change, but also that **you will need to restart your Rails application if you make any changes to the gem**.
73
-
74
- ## Testing the Node package for React on Rails via Yalc
75
-
76
- In addition to testing the Ruby parts out, you can also test the Node package parts of the gem with an external application. First, be **sure** to build the NPM package:
77
-
78
- ```sh
79
- cd react_on_rails/
80
- yarn
81
-
82
- # Update the lib directory with babel compiled files
83
- yarn run build-watch
84
- ```
85
-
86
- You need to do this once:
87
-
88
- ```
89
- # Will send the updates to other folders
90
- yalc publish
91
- cd spec/dummy
92
- yalc add react-on-rails
93
- ```
94
-
95
- The workflow is:
96
-
97
- 1. Make changes to the node package.
98
- 2. **CRITICAL**: Run yalc push to send updates to all linked apps:
99
-
100
- ```
101
- cd <top dir>
102
- # Will send the updates to other folders - MUST DO THIS AFTER ANY CHANGES
103
- yalc push
104
- cd spec/dummy
105
-
106
- # Will update from yalc
107
- yarn
108
- ```
109
-
110
- **⚠️ Common Mistake**: Forgetting to run `yalc push` after making changes to React on Rails source code will result in test apps not receiving updates, making it appear that your changes have no effect.
111
-
112
- When you run `yalc push`, you'll get an informative message
113
-
114
- ```
115
- βœ— yalc push
116
- react-on-rails@12.0.0-12070fd1 published in store.
117
- Pushing react-on-rails@12.0.0 in /Users/justin/shakacode/react-on-rails/react_on_rails/spec/dummy
118
- Package react-on-rails@12.0.0-12070fd1 added ==> /Users/justin/shakacode/react-on-rails/react_on_rails/spec/dummy/node_modules/react-on-rails.
119
- Don't forget you may need to run yarn after adding packages with yalc to install/update dependencies/bin scripts.
120
- ```
121
-
122
- #### Example: Testing NPM changes with the dummy app
123
-
124
- 1. Add `console.log('Hello!')` to [clientStartup.ts, function render](https://github.com/shakacode/react_on_rails/blob/master/node_package/src/clientStartup.ts in `/node_package/src/clientStartup.js` to confirm we're getting an update to the node package client side. Do the same for function `serverRenderReactComponent` in `/node_package/src/serverRenderReactComponent.ts`.
125
- 2. Refresh the browser if the server is already running or start the server using `foreman start` from `react_on_rails/spec/dummy` and navigate to `http://localhost:5000/`. You will now see the `Hello!` message printed in the browser's console. If you did not see that message, then review the steps above for the workflow of making changes and pushing them via yalc.
126
-
127
- # Development Setup for Gem and Node Package Contributors
128
-
129
- ## Dev Initial Setup
130
-
131
- ### Prereqs
132
-
133
- After checking out the repo, making sure you have Ruby and Node version managers set up (such as rvm and nvm, or rbenv and nodenv, etc.), 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.
134
-
135
- ### Local Node Package
136
-
137
- Note, the example and dummy apps will use your local `node_packages` folder as the `react-on-rails` node package. This will also be done automatically for you via the `rake examples:gen_all` rake task.
138
-
139
- _Side note: It's critical to use the alias section of the Webpack config to avoid a double inclusion error. This has already been done for you in the example and dummy apps, but for reference:_
140
-
141
- ```js
142
- resolve: {
143
- alias: {
144
- react: path.resolve('./node_modules/react'),
145
- 'react-dom': path.resolve('./node_modules/react-dom'),
146
- },
147
- },
148
- ```
149
-
150
- ### Install NPM dependencies and build the NPM package for react-on-rails
151
-
152
- ```sh
153
- cd react_on_rails/
154
- yarn
155
- yarn build
156
- ```
157
-
158
- Or run this, which builds the Yarn package, then the Webpack files for `spec/dummy`, and runs tests in
159
- `spec/dummy`.
160
-
161
- ```sh
162
- # Optionally change default capybara driver
163
- export DRIVER=selenium_firefox
164
- cd react_on_rails/
165
- yarn run dummy:spec
166
- ```
167
-
168
- To convert the development environment over to Shakapacker v6 instead of the default Shakapacker v8:
169
-
170
- ```sh
171
- # Optionally change default capybara driver
172
- export DRIVER=selenium_firefox
173
- cd react_on_rails/
174
- script/convert
175
- yarn run dummy:spec
176
- ```
177
-
178
- ## Running tests
179
-
180
- ### JS tests
181
-
182
- ```sh
183
- cd react_on_rails/
184
- yarn run test
185
- ```
186
-
187
- ### spec/dummy tests
188
-
189
- ```sh
190
- cd react_on_rails/spec/dummy
191
- rspec
192
- ```
193
-
194
- ### Linting, type checking and JS tests together
195
-
196
- ```sh
197
- cd react_on_rails/
198
- yarn run check
199
- ```
200
-
201
- ## Development Commands
202
-
203
- ### Code Formatting
204
-
205
- To format JavaScript/TypeScript files with Prettier:
206
-
207
- ```sh
208
- yarn start format
209
- ```
210
-
211
- To check formatting without fixing:
212
-
213
- ```sh
214
- yarn start format.listDifferent
215
- ```
216
-
217
- ### Linting
218
-
219
- Run all linters (ESLint and RuboCop):
220
-
221
- ```sh
222
- rake lint
223
- ```
224
-
225
- Run only RuboCop:
226
-
227
- ```sh
228
- rake lint:rubocop
229
- ```
230
-
231
- Run only ESLint:
232
-
233
- ```sh
234
- yarn run lint
235
- ```
236
-
237
- ### Starting the Dummy App
238
-
239
- To run the dummy app, it's **CRITICAL** to not just run `rails s`. You have to run `foreman start` with one of the Procfiles. If you don't do this, then `webpack` will not generate a new bundle, and you will be seriously confused when you change JavaScript and the app does not change. If you change the Webpack configs, then you need to restart Foreman. If you change the JS code for react-on-rails, you need to run `yarn run build` in the project root.
240
-
241
- ### RSpec Testing
242
-
243
- Run `rake` for testing the gem and `spec/dummy`. Otherwise, the `rspec` command only works for testing within the sample apps, like `spec/dummy`.
244
-
245
- If you run `rspec` at the top level, you'll see this message: `require': cannot load such file -- rails_helper (LoadError)`
246
-
247
- After running a test, you can view the coverage results SimpleCov reports by opening `coverage/index.html`.
248
-
249
- Turbolinks 5 is included in the test app, unless "DISABLE_TURBOLINKS" is set to YES in the environment.
250
-
251
- Run `rake -T` or `rake -D` to see testing options.
252
-
253
- `rake all_but_examples` is typically best for developers, except if any generators changed.
254
-
255
- See below for verifying changes to the generators.
256
-
257
- ### Install Generator
258
-
259
- In your Rails app add this gem with a path to your fork.
260
-
261
- ```ruby
262
- gem 'react_on_rails', path: '../relative/path/to/react_on_rails'
263
- ```
264
-
265
- Then run `bundle`.
266
-
267
- The main installer can be run with `./bin/rails generate react_on_rails:install`
268
-
269
- Then use yalc to add the npm module.
270
-
271
- Be sure that your ran this first at the top level of React on Rails
272
-
273
- ```
274
- yalc publish
275
- ```
276
-
277
- Then add the node package to your test app:
278
-
279
- ```
280
- yalc add react-on-rails
281
- ```
282
-
283
- ### Testing the Generator
284
-
285
- The generators are covered by generator tests using Rails's generator testing helpers, but it never hurts to do a sanity check and explore the API. See [generator-testing.md](docs/contributor-info/generator-testing.md) for a script on how to run the generator on a fresh project.
286
-
287
- `rake run_rspec:shakapacker_examples_basic` is a great way to run tests on one generator. Once that works, you should run `rake run_rspec:shakapacker_examples`. Be aware that this will create a huge number of files under a `/gen-examples` directory. You should be sure to exclude this directory from your IDE and delete it once your testing is done.
288
-
289
- #### Manual Generator Testing Workflow
290
-
291
- For comprehensive testing of generator changes, use this manual testing workflow with dedicated test applications:
292
-
293
- **1. Set up test application with clean baseline:**
294
-
295
- ```bash
296
- # Create a test Rails app
297
- mkdir -p {project_dir}/test-app
298
- cd {project_dir}/test-app
299
- rails new . --skip-javascript
300
-
301
- # Set up for testing the generator
302
- echo 'gem "react_on_rails", path: "../react_on_rails"' >> Gemfile
303
- yalc add react-on-rails
304
-
305
- # Create a clean baseline tag for testing
306
- git init && git add . && git commit -m "Initial commit"
307
- git tag generator_testing_base
308
- bundle install
309
-
310
- # Clean reset to baseline state
311
- git clean -fd && git reset --hard && git clean -fd
312
- ```
313
-
314
- **2. Test generator commits systematically:**
315
-
316
- When testing specific generator improvements or fixes, test both Shakapacker scenarios:
317
-
318
- **Scenario A: No Shakapacker installed (fresh Rails app)**
319
-
320
- ```bash
321
- # Reset to clean baseline before each test
322
- git clean -fd && git reset --hard generator_testing_base && git clean -fd
323
-
324
- # Ensure no Shakapacker in Gemfile (remove if present)
325
- # Edit Gemfile to update gem path: gem 'react_on_rails', path: '../path/to/main/repo'
326
- bundle install
327
-
328
- # Run generator - should install Shakapacker automatically
329
- ./bin/rails generate react_on_rails:install
330
-
331
- # Verify Shakapacker was added to Gemfile and installed correctly
332
- ```
333
-
334
- **Scenario B: Shakapacker already installed**
335
-
336
- ```bash
337
- # Reset to clean baseline
338
- git clean -fd && git reset --hard generator_testing_base && git clean -fd
339
-
340
- # Add Shakapacker to Gemfile
341
- bundle add shakapacker --strict
342
-
343
- # Run Shakapacker installer first
344
- ./bin/rails shakapacker:install
345
-
346
- # Edit Gemfile to update gem path: gem 'react_on_rails', path: '../path/to/main/repo'
347
- bundle install
348
-
349
- # Run generator - should detect existing Shakapacker
350
- ./bin/rails generate react_on_rails:install
351
-
352
- # Verify generator adapts to existing Shakapacker setup
353
- ```
354
-
355
- **3. Document testing results:**
356
-
357
- For each commit tested, document:
358
-
359
- - Generator execution success/failure for both scenarios
360
- - Shakapacker installation/detection behavior
361
- - Component rendering in browser
362
- - Console output and warnings
363
- - File generation differences between scenarios
364
- - Specific issues found
365
-
366
- This systematic approach ensures generator changes work correctly whether Shakapacker is pre-installed or needs to be installed by the generator.
367
-
368
- #### Testing Generator with Yalc for React Component Functionality
369
-
370
- When testing the install generator with new Rails apps, you need to use **yalc** for the JavaScript package to ensure React components work correctly. The Ruby gem path reference is insufficient for client-side rendering.
371
-
372
- **Problem**: Using only the gem path (`gem "react_on_rails", path: "../path"`) in a new Rails app results in React components not mounting on the client side, even though server-side rendering works fine.
373
-
374
- **Solution**: Use both gem path and yalc for complete testing:
375
-
376
- ```ruby
377
- # In test app's Gemfile
378
- gem 'react_on_rails', path: '../relative/path/to/react_on_rails'
379
- ```
380
-
381
- ```bash
382
- # After running the install generator AND after making any changes to the React on Rails source code
383
- cd /path/to/react_on_rails
384
- npm run build
385
- npx yalc publish
386
- # CRITICAL: Push changes to all linked apps
387
- npx yalc push
388
-
389
- cd /path/to/test_app
390
- npm install
391
-
392
- # Restart development server
393
- bin/dev
394
- ```
395
-
396
- **⚠️ CRITICAL DEBUGGING NOTE:**
397
- Always run `yalc push` after making changes to React on Rails source code. Without this step, your test app won't receive the updated package, leading to confusing behavior where changes appear to have no effect.
398
-
399
- **Alternative to Yalc: npm pack (More Reliable)**
400
- For a more reliable alternative that exactly mimics real package installation:
401
-
402
- ```bash
403
- # In react_on_rails directory
404
- npm run build
405
- npm pack # Creates react-on-rails-15.0.0.tgz
406
-
407
- # In test app directory
408
- npm install ../path/to/react_on_rails/react-on-rails-15.0.0.tgz
409
- ```
410
-
411
- This approach:
412
-
413
- - βœ… Exactly mimics real package installation
414
- - βœ… No symlink issues across different filesystems
415
- - βœ… More reliable for CI/CD testing
416
- - ⚠️ Requires manual step after each change (can be scripted)
417
-
418
- **Why this is needed**:
419
-
420
- - The gem provides Rails integration and server-side rendering
421
- - Yalc provides the complete JavaScript client library needed for component mounting
422
- - Without yalc, you'll see empty divs where React components should render
423
-
424
- **Verification**:
425
-
426
- - Visit the hello_world page in browser
427
- - Check browser console for "RENDERED HelloWorld to dom node" success message
428
- - Confirm React component is interactive (input field updates name display)
429
-
430
- **Development Mode Console Output**:
431
-
432
- - `bin/dev` (HMR): Shows HMR warnings and resource preload warnings (expected)
433
- - `bin/dev static`: Shows only resource preload warnings (cleaner output)
434
- - `bin/dev prod`: Cleanest output with minimal warnings (production-like environment)
435
-
436
- **Note**: Resource preload warnings in development modes are normal and can be ignored. They occur because Shakapacker generates preload tags but scripts load asynchronously. Production mode eliminates most of these warnings.
437
-
438
- #### Generator Testing Troubleshooting
439
-
440
- **Common Issues and Solutions:**
441
-
442
- 1. **React components not rendering (empty divs)**
443
-
444
- - **Cause**: Missing yalc setup for JavaScript package
445
- - **Solution**: Follow yalc setup steps above after running generator
446
-
447
- 2. **Generator fails with Shakapacker errors**
448
-
449
- - **Cause**: Conflicting Shakapacker versions or incomplete installation
450
- - **Solution**: Clean reset and ensure consistent Shakapacker version across tests
451
-
452
- 3. **Babel configuration conflicts during yalc development**
453
-
454
- - **Cause**: Both `babel.config.js` and `package.json` "babel" section defining presets
455
- - **Solution**: Remove "babel" section from `package.json`, keep only `babel.config.js`
456
-
457
- 4. **"Package.json not found" errors**
458
-
459
- - **Cause**: Generator trying to access non-existent package.json files
460
- - **Solution**: Test with commits that fix this specific issue (e.g., bc69dcd0)
461
-
462
- 5. **Port conflicts during testing**
463
- - **Cause**: Multiple development servers running
464
- - **Solution**: Run `bin/dev kill` before starting new test servers
465
-
466
- **Testing Best Practices:**
467
-
468
- - Always use the double clean command: `git clean -fd && git reset --hard && git clean -fd`
469
- - Test both Shakapacker scenarios for comprehensive coverage
470
- - Document exact error messages and steps to reproduce
471
- - Verify React component interactivity, not just rendering
472
- - Test all development modes: `bin/dev`, `bin/dev static`, `bin/dev prod`
473
-
474
- ## Pre-Commit Requirements
475
-
476
- **AUTOMATED**: If you've set up Lefthook (see Prerequisites), linting runs automatically on changed files before each commit.
477
-
478
- **MANUAL OPTION**: If you need to run linting manually:
479
-
480
- ```bash
481
- # Navigate to the main react_on_rails directory
482
- cd react_on_rails/
483
-
484
- # Run Prettier for JavaScript/TypeScript formatting
485
- yarn run format
486
-
487
- # Run ESLint for JavaScript/TypeScript linting
488
- yarn run lint
489
-
490
- # Run RuboCop for Ruby linting and formatting
491
- rake lint:rubocop
492
-
493
- # Or run all linters together
494
- rake lint
495
- ```
496
-
497
- **Git hooks automatically run:**
498
-
499
- - Format JavaScript/TypeScript files with Prettier (on changed files only)
500
- - Check and fix linting issues with ESLint
501
- - Check and fix Ruby style issues with RuboCop (on all changed files)
502
- - Ensure trailing newlines on all files
503
-
504
- **Setup**: Automatic during normal development setup
505
-
506
- ## πŸ€– Best Practices for AI Coding Agents
507
-
508
- **CRITICAL WORKFLOW** to prevent CI failures:
509
-
510
- ### 1. **After Making Code Changes**
511
-
512
- ```bash
513
- # Auto-fix all linting violations after code changes
514
- rake autofix
515
- ```
516
-
517
- ### 2. **Common AI Agent Mistakes**
518
-
519
- ❌ **DON'T:**
520
-
521
- - Commit code that hasn't been linted locally
522
- - Ignore formatting rules when creating new files
523
- - Add manual formatting that conflicts with Prettier/RuboCop
524
-
525
- βœ… **DO:**
526
-
527
- - Run `rake lint` after any code changes
528
- - Use `rake autofix` to automatically fix all linting violations
529
- - Create new files that follow existing patterns
530
- - Test locally before committing
531
-
532
- ### 4. **Template File Best Practices**
533
-
534
- When creating new template files (`.jsx`, `.rb`, etc.):
535
-
536
- 1. Copy existing template structure and patterns
537
- 2. Run `yarn run eslint . --fix` immediately after creation
538
- 3. Verify with `rake lint` before committing
539
-
540
- ### 5. **RuboCop Complexity Issues**
541
-
542
- For methods with high ABC complexity (usually formatting/display methods):
543
-
544
- ```ruby
545
- # rubocop:disable Metrics/AbcSize
546
- def complex_formatting_method
547
- # ... method with lots of string interpolation/formatting
548
- end
549
- # rubocop:enable Metrics/AbcSize
550
- ```
551
-
552
- **Remember**: Failing CI wastes time and resources. Always lint locally first!
553
-
554
- ### Linting
555
-
556
- All linting is performed from the docker container for CI. You will need docker and docker-compose installed locally to lint code changes via the lint container. You can lint locally by running `npm run lint && npm run flow`
557
-
558
- - [Install Docker Toolbox for Mac](https://www.docker.com/toolbox)
559
- - [Install Docker Compose for Linux](https://docs.docker.com/compose/install/)
560
-
561
- Once you have docker and docker-compose running locally, run `docker-compose build lint`. This will build the `reactonrails_lint` docker image and docker-compose `lint` container. The initial build is slow, but after the install, startup is very quick.
562
-
563
- ### Linting Commands
564
-
565
- Run `rake lint`.
566
-
567
- Alternately with Docker:
568
-
569
- Run `rake -D docker` to see all docker linting commands for rake. `rake docker:lint` will run all linters. For individual rake linting commands please refer to `rake -D docker` for the list.
570
-
571
- You can run specific linting for directories or files by using `docker-compose run lint rubocop (file path or directory)`, etc.
572
-
573
- `docker-compose run lint bash` sets you up to run from the container command line.
574
-
575
- ### Updating Rubocop
576
-
577
- 2 files require updating to update the Rubocop version:
578
-
579
- 1. `react_on_rails.gemspec`
580
- 2. `spec/dummy/Gemfile`
581
-
582
- ### Docker CI - Test and Linting
583
-
584
- Docker CI and Tests containers have a xvfd server automatically started for headless browser testing with selenium and Firefox.
585
-
586
- Run `docker-compose build ci` to build the CI container. Run `docker-compose run ci` to start all rspec tests and linting. `docker-compose run --entrypoint=/bin/bash` will override the default CI action and place you inside the CI container in a bash session. This is what is run on Travis-CI.
587
-
588
- Run `docker-compose build tests` to build the tests container. Run `docker-compose run tests` to start all RSpec tests.
589
-
590
- # Advice for Project Maintainers and Contributors
591
-
592
- What do project maintainers do? What sort of work is involved? [sstephenson](https://github.com/sstephenson) wrote in the [turbolinks](https://github.com/turbolinks/turbolinks) repo:
593
-
594
- > [Why this is not still fully merged?](https://github.com/turbolinks/turbolinks/pull/124#issuecomment-239826060)
595
-
596
- # πŸ“¦ Demo Naming and README Standards
597
-
598
- To keep our React on Rails demos clear, discoverable, and SEO-friendly, all demo repos follow a standardized naming and documentation structure.
599
-
600
- ---
601
-
602
- ## βœ… Repository Naming Convention
603
-
604
- Use the format:
605
-
606
- ```
607
- react_on_rails-demo-v[REACT_ON_RAILS_VERSION]-[key-topics]
608
- ```
609
-
610
- **Examples:**
611
-
612
- - `react_on_rails-demo-v15-ssr-auto-registration-bundle-splitting`
613
- - `react_on_rails-demo-v15-react-server-components`
614
- - `react_on_rails-demo-v15-typescript-setup`
615
- - `react_on_rails-demo-v15-cypress-setup`
616
-
617
- **Why this format?**
618
-
619
- - Clear versioning and purpose
620
- - Easy to discover in GitHub, search engines, and documentation
621
- - Consistent prefix for grouping demos together
622
-
623
- ---
624
-
625
- ## πŸ“ README Title Format
626
-
627
- ```
628
- # React on Rails Demo: [Topics] with v[VERSION] and Rails [VERSION]
629
- ```
630
-
631
- **Example:**
632
-
633
- ```
634
- # React on Rails Demo: SSR, Auto-Registration & Bundle Splitting with v15 and Rails 8
635
- ```
636
-
637
- ---
638
-
639
- ## πŸ“„ README Description Template
640
-
641
- ```
642
- A fully working demo of React on Rails v[VERSION] on Rails [VERSION], showcasing [topics].
643
-
644
- βœ… Includes:
645
- - [Topic 1]
646
- - [Topic 2]
647
- - [Topic 3]
648
-
649
- πŸ“‚ Repo name: `react_on_rails-demo-v[VERSION]-[topics]`
650
-
651
- πŸ“š Part of the [React on Rails Demo Series](https://github.com/shakacode?tab=repositories&q=react_on_rails-demo)
652
- ```
653
-
654
- **Example:**
655
-
656
- ```
657
- A fully working demo of React on Rails v15 on Rails 8, showcasing server-side rendering, file-system-based auto-registration, and intelligent bundle splitting.
658
-
659
- βœ… Includes:
660
- - Server-Side Rendering (SSR)
661
- - Auto-discovered components based on file structure
662
- - Lightweight vs. heavy component splitting
663
- - Fix for β€œpackage.json not found” install bug
664
-
665
- πŸ“‚ Repo name: `react_on_rails-demo-v15-ssr-auto-registration-bundle-splitting`
666
-
667
- πŸ“š Part of the [React on Rails Demo Series](https://github.com/shakacode?tab=repositories&q=react_on_rails-demo)
668
- ```
data/Dockerfile_tests DELETED
@@ -1,12 +0,0 @@
1
- FROM dylangrafmyre/docker-ci
2
-
3
- WORKDIR /app/
4
-
5
- COPY ["/lib/react_on_rails/version.rb", "/app/lib/react_on_rails/"]
6
- COPY ["Gemfile", "Gemfile.lock", "react_on_rails.gemspec", "rakelib/", "/app/"]
7
- COPY ["/spec/dummy/Gemfile", "/spec/dummy/Gemfile.lock", "/app/spec/dummy/"]
8
- RUN bundle install --gemfile=spec/dummy/Gemfile
9
-
10
- ENV DISPLAY :99
11
- ENTRYPOINT service xvfd start \
12
- && rake