react_on_rails 14.2.1 β 16.1.1
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.
- checksums.yaml +4 -4
- data/AI_AGENT_INSTRUCTIONS.md +63 -0
- data/CHANGELOG.md +564 -85
- data/CLAUDE.md +135 -0
- data/CODING_AGENTS.md +313 -0
- data/CONTRIBUTING.md +448 -37
- data/Gemfile.development_dependencies +6 -1
- data/Gemfile.lock +13 -4
- data/KUDOS.md +22 -1
- data/LICENSE.md +30 -4
- data/LICENSES/README.md +14 -0
- data/NEWS.md +48 -48
- data/PROJECTS.md +45 -40
- data/REACT-ON-RAILS-PRO-LICENSE.md +129 -0
- data/README.md +113 -42
- data/SUMMARY.md +62 -52
- data/TODO.md +135 -0
- data/bin/lefthook/check-trailing-newlines +38 -0
- data/bin/lefthook/get-changed-files +26 -0
- data/bin/lefthook/prettier-format +26 -0
- data/bin/lefthook/ruby-autofix +26 -0
- data/bin/lefthook/ruby-lint +27 -0
- data/eslint.config.ts +232 -0
- data/knip.ts +40 -6
- data/lib/generators/USAGE +4 -5
- data/lib/generators/react_on_rails/USAGE +65 -0
- data/lib/generators/react_on_rails/base_generator.rb +276 -62
- data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -0
- data/lib/generators/react_on_rails/generator_helper.rb +35 -1
- data/lib/generators/react_on_rails/generator_messages.rb +138 -17
- data/lib/generators/react_on_rails/install_generator.rb +474 -26
- data/lib/generators/react_on_rails/react_no_redux_generator.rb +19 -6
- data/lib/generators/react_on_rails/react_with_redux_generator.rb +110 -18
- data/lib/generators/react_on_rails/templates/.eslintrc +1 -1
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +5 -0
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-prod-assets +8 -0
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-static-assets +2 -0
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +0 -5
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css +2 -2
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorldServer.js +1 -1
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/packs/server-bundle.js +1 -8
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.client.jsx +21 -0
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.client.tsx +25 -0
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.module.css +4 -0
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.server.jsx +5 -0
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.server.tsx +5 -0
- data/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt +1 -1
- data/lib/generators/react_on_rails/templates/base/base/app/views/layouts/hello_world.html.erb +4 -2
- data/lib/generators/react_on_rails/templates/base/base/babel.config.js.tt +5 -2
- data/lib/generators/react_on_rails/templates/base/base/bin/dev +34 -0
- data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb.tt +14 -5
- data/lib/generators/react_on_rails/templates/base/base/config/shakapacker.yml +76 -7
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt +1 -1
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/development.js.tt +6 -10
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/production.js.tt +2 -2
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/serverWebpackConfig.js.tt +3 -2
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/test.js.tt +2 -2
- data/lib/generators/react_on_rails/templates/dev_tests/spec/system/hello_world_spec.rb +0 -2
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/actions/helloWorldActionCreators.ts +18 -0
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +0 -6
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css +4 -0
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.tsx +24 -0
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/constants/helloWorldConstants.ts +6 -0
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/containers/HelloWorldContainer.ts +20 -0
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/reducers/helloWorldReducer.js +1 -1
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/reducers/helloWorldReducer.ts +22 -0
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/startup/HelloWorldApp.client.tsx +23 -0
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/startup/HelloWorldApp.server.jsx +5 -0
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/startup/HelloWorldApp.server.tsx +5 -0
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/store/helloWorldStore.ts +18 -0
- data/lib/react_on_rails/configuration.rb +141 -57
- data/lib/react_on_rails/controller.rb +6 -2
- data/lib/react_on_rails/dev/file_manager.rb +78 -0
- data/lib/react_on_rails/dev/pack_generator.rb +27 -0
- data/lib/react_on_rails/dev/process_manager.rb +61 -0
- data/lib/react_on_rails/dev/server_manager.rb +487 -0
- data/lib/react_on_rails/dev.rb +20 -0
- data/lib/react_on_rails/doctor.rb +1149 -0
- data/lib/react_on_rails/engine.rb +6 -0
- data/lib/react_on_rails/git_utils.rb +12 -2
- data/lib/react_on_rails/helper.rb +176 -74
- data/lib/react_on_rails/json_parse_error.rb +6 -1
- data/lib/react_on_rails/packer_utils.rb +61 -71
- data/lib/react_on_rails/packs_generator.rb +221 -19
- data/lib/react_on_rails/prerender_error.rb +4 -0
- data/lib/react_on_rails/pro/NOTICE +21 -0
- data/lib/react_on_rails/pro/helper.rb +122 -0
- data/lib/react_on_rails/pro/utils.rb +53 -0
- data/lib/react_on_rails/react_component/render_options.rb +38 -6
- data/lib/react_on_rails/server_rendering_js_code.rb +0 -1
- data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +12 -5
- data/lib/react_on_rails/system_checker.rb +659 -0
- data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +1 -1
- data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +6 -4
- data/lib/react_on_rails/test_helper.rb +2 -3
- data/lib/react_on_rails/utils.rb +139 -43
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/react_on_rails/version_checker.rb +14 -20
- data/lib/react_on_rails/version_syntax_converter.rb +1 -1
- data/lib/react_on_rails.rb +1 -0
- data/lib/tasks/assets.rake +1 -1
- data/lib/tasks/doctor.rake +48 -0
- data/lib/tasks/generate_packs.rake +158 -1
- data/react_on_rails.gemspec +1 -0
- data/tsconfig.eslint.json +6 -0
- data/tsconfig.json +5 -3
- metadata +63 -14
- data/REACT-ON-RAILS-PRO-LICENSE +0 -95
- data/lib/generators/react_on_rails/adapt_for_older_shakapacker_generator.rb +0 -41
- data/lib/generators/react_on_rails/bin/dev +0 -30
- data/lib/generators/react_on_rails/bin/dev-static +0 -30
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-static.tt +0 -9
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt +0 -5
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/packs/registration.js.tt +0 -8
- /data/lib/generators/react_on_rails/templates/base/base/config/webpack/{webpackConfig.js.tt β generateWebpackConfigs.js.tt} +0 -0
- /data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/startup/{HelloWorldApp.jsx β HelloWorldApp.client.jsx} +0 -0
data/CONTRIBUTING.md
CHANGED
@@ -1,12 +1,30 @@
|
|
1
1
|
# Tips for Contributors
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
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:
|
6
27
|
|
7
|
-
## To run tests:
|
8
|
-
* [Yalc](https://github.com/whitecolor/yalc) must be installed globally for most local development.
|
9
|
-
* After updating code via Git, to prepare all examples:
|
10
28
|
```sh
|
11
29
|
cd react_on_rails/
|
12
30
|
bundle && yarn && rake shakapacker_examples:gen_all && rake node_package && rake
|
@@ -16,23 +34,26 @@ See [Dev Initial Setup](#dev-initial-setup) below for, well... initial setup,
|
|
16
34
|
and [Running tests](#running-tests) for more details on running tests.
|
17
35
|
|
18
36
|
# IDE/IDE SETUP
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
32
51
|
|
33
52
|
# Configuring your test app to use your local fork
|
53
|
+
|
34
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.
|
35
|
-
|
55
|
+
|
56
|
+
```text
|
36
57
|
βββ test_app
|
37
58
|
| βββ client
|
38
59
|
βββ react_on_rails
|
@@ -41,6 +62,7 @@ You can test the `react-on-rails` gem using your own external test app or the ge
|
|
41
62
|
```
|
42
63
|
|
43
64
|
## Testing the Ruby Gem
|
65
|
+
|
44
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:
|
45
67
|
|
46
68
|
```ruby
|
@@ -49,8 +71,9 @@ gem "react_on_rails", path: "../path-to-react-on-rails"
|
|
49
71
|
|
50
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**.
|
51
73
|
|
52
|
-
## Testing the Node package for
|
53
|
-
|
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:
|
54
77
|
|
55
78
|
```sh
|
56
79
|
cd react_on_rails/
|
@@ -70,11 +93,13 @@ yalc add react-on-rails
|
|
70
93
|
```
|
71
94
|
|
72
95
|
The workflow is:
|
96
|
+
|
73
97
|
1. Make changes to the node package.
|
74
|
-
2.
|
98
|
+
2. **CRITICAL**: Run yalc push to send updates to all linked apps:
|
99
|
+
|
75
100
|
```
|
76
101
|
cd <top dir>
|
77
|
-
# Will send the updates to other folders
|
102
|
+
# Will send the updates to other folders - MUST DO THIS AFTER ANY CHANGES
|
78
103
|
yalc push
|
79
104
|
cd spec/dummy
|
80
105
|
|
@@ -82,6 +107,8 @@ cd spec/dummy
|
|
82
107
|
yarn
|
83
108
|
```
|
84
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
|
+
|
85
112
|
When you run `yalc push`, you'll get an informative message
|
86
113
|
|
87
114
|
```
|
@@ -93,6 +120,7 @@ Don't forget you may need to run yarn after adding packages with yalc to install
|
|
93
120
|
```
|
94
121
|
|
95
122
|
#### Example: Testing NPM changes with the dummy app
|
123
|
+
|
96
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`.
|
97
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.
|
98
126
|
|
@@ -101,13 +129,14 @@ Don't forget you may need to run yarn after adding packages with yalc to install
|
|
101
129
|
## Dev Initial Setup
|
102
130
|
|
103
131
|
### Prereqs
|
104
|
-
|
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.
|
105
134
|
|
106
135
|
### Local Node Package
|
107
136
|
|
108
|
-
Note, the example and dummy apps will use your local
|
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.
|
109
138
|
|
110
|
-
|
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:_
|
111
140
|
|
112
141
|
```js
|
113
142
|
resolve: {
|
@@ -126,9 +155,8 @@ yarn
|
|
126
155
|
yarn build
|
127
156
|
```
|
128
157
|
|
129
|
-
Or run this which builds the
|
130
|
-
spec/dummy
|
131
|
-
|
158
|
+
Or run this, which builds the Yarn package, then the Webpack files for `spec/dummy`, and runs tests in
|
159
|
+
`spec/dummy`.
|
132
160
|
|
133
161
|
```sh
|
134
162
|
# Optionally change default capybara driver
|
@@ -170,10 +198,48 @@ cd react_on_rails/
|
|
170
198
|
yarn run check
|
171
199
|
```
|
172
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
|
+
|
173
237
|
### Starting the Dummy App
|
174
|
-
|
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.
|
175
240
|
|
176
241
|
### RSpec Testing
|
242
|
+
|
177
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`.
|
178
244
|
|
179
245
|
If you run `rspec` at the top level, you'll see this message: `require': cannot load such file -- rails_helper (LoadError)`
|
@@ -189,15 +255,16 @@ Run `rake -T` or `rake -D` to see testing options.
|
|
189
255
|
See below for verifying changes to the generators.
|
190
256
|
|
191
257
|
### Install Generator
|
258
|
+
|
192
259
|
In your Rails app add this gem with a path to your fork.
|
193
260
|
|
194
261
|
```ruby
|
195
262
|
gem 'react_on_rails', path: '../relative/path/to/react_on_rails'
|
196
|
-
```
|
263
|
+
```
|
197
264
|
|
198
265
|
Then run `bundle`.
|
199
266
|
|
200
|
-
The main installer can be run with
|
267
|
+
The main installer can be run with `./bin/rails generate react_on_rails:install`
|
201
268
|
|
202
269
|
Then use yalc to add the npm module.
|
203
270
|
|
@@ -214,19 +281,287 @@ yalc add react-on-rails
|
|
214
281
|
```
|
215
282
|
|
216
283
|
### Testing the Generator
|
217
|
-
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_script.md](generator_testing_script.md) for a script on how to run the generator on a fresh project.
|
218
284
|
|
219
|
-
|
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!
|
220
553
|
|
221
554
|
### Linting
|
555
|
+
|
222
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`
|
223
557
|
|
224
|
-
|
225
|
-
|
558
|
+
- [Install Docker Toolbox for Mac](https://www.docker.com/toolbox)
|
559
|
+
- [Install Docker Compose for Linux](https://docs.docker.com/compose/install/)
|
226
560
|
|
227
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.
|
228
562
|
|
229
563
|
### Linting Commands
|
564
|
+
|
230
565
|
Run `rake lint`.
|
231
566
|
|
232
567
|
Alternately with Docker:
|
@@ -238,12 +573,14 @@ You can run specific linting for directories or files by using `docker-compose r
|
|
238
573
|
`docker-compose run lint bash` sets you up to run from the container command line.
|
239
574
|
|
240
575
|
### Updating Rubocop
|
576
|
+
|
241
577
|
2 files require updating to update the Rubocop version:
|
242
578
|
|
243
579
|
1. `react_on_rails.gemspec`
|
244
580
|
2. `spec/dummy/Gemfile`
|
245
581
|
|
246
582
|
### Docker CI - Test and Linting
|
583
|
+
|
247
584
|
Docker CI and Tests containers have a xvfd server automatically started for headless browser testing with selenium and Firefox.
|
248
585
|
|
249
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.
|
@@ -255,3 +592,77 @@ Run `docker-compose build tests` to build the tests container. Run `docker-compo
|
|
255
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:
|
256
593
|
|
257
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
|
+
```
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
gem "shakapacker", "8.
|
3
|
+
gem "shakapacker", "8.2.0"
|
4
4
|
gem "bootsnap", require: false
|
5
5
|
gem "rails", "~> 7.1"
|
6
6
|
|
@@ -38,6 +38,11 @@ group :development, :test do
|
|
38
38
|
gem "rubocop-rspec", "~>2.26", require: false
|
39
39
|
gem "scss_lint", require: false
|
40
40
|
gem "spring", "~> 4.0"
|
41
|
+
gem "lefthook", require: false
|
42
|
+
# Added for Ruby 3.5+ compatibility to silence warnings
|
43
|
+
gem "benchmark", require: false
|
44
|
+
gem "logger", require: false
|
45
|
+
gem "ostruct", require: false
|
41
46
|
end
|
42
47
|
|
43
48
|
group :test do
|