Skip to content

Commit 2316acd

Browse files
justin808claude
andcommitted
Unify bin/dev script and improve cleaning logic
- Replace bin/dev-static with unified bin/dev script supporting multiple modes - Add targeted cleaning to remove only non-generated files from pack directories - Refactor cleaning methods to reduce complexity per RuboCop suggestions - Update all documentation to reference 'bin/dev static' instead of 'bin/dev-static' - Remove obsolete dev-static generator file and associated tests 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 7c0dfa3 commit 2316acd

File tree

13 files changed

+246
-165
lines changed

13 files changed

+246
-165
lines changed

CHANGELOG.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@ for details.
442442
- Removal of config.symlink_non_digested_assets_regex as it's no longer needed with rails/webpacker.
443443
If any business needs this, we can move the code to a separate gem.
444444
- Added configuration option `same_bundle_for_client_and_server` with default `false` because
445-
446445
1. Production applications would typically have a server bundle that differs from the client bundle
447446
2. This change only affects trying to use HMR with react_on_rails with rails/webpacker.
448447

@@ -1160,13 +1159,11 @@ No changes.
11601159
- Added automatic compilation of assets at precompile is now done by ReactOnRails. Thus, you don't need to provide your own `assets.rake` file that does the precompilation.
11611160
[#398](https://github.com/shakacode/react_on_rails/pull/398) by [robwise](https://github.com/robwise), [jbhatab](https://github.com/jbhatab), and [justin808](https://github.com/justin808).
11621161
- **Migration to v6**
1163-
11641162
- Do not run the generator again if you've already run it.
11651163

11661164
- See [shakacode/react-webpack-rails-tutorial/pull/287](https://github.com/shakacode/react-webpack-rails-tutorial/pull/287) for an example of upgrading from v5.
11671165

11681166
- To configure the asset compilation you can either
1169-
11701167
1. Specify a `config/react_on_rails` setting for `build_production_command` to be nil to turn this feature off.
11711168
2. Specify the script command you want to run to build your production assets, and remove your `assets.rake` file.
11721169

CODING_AGENTS.md

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This guide provides specific guidelines for AI coding agents (like Claude Code)
55
## Quick Reference Commands
66

77
### Essential Commands
8+
89
```bash
910
# Install dependencies
1011
bundle && yarn
@@ -13,7 +14,7 @@ bundle && yarn
1314
bundle exec rspec # All tests (from project root)
1415
cd spec/dummy && bundle exec rspec # Dummy app tests only
1516

16-
# Linting & Formatting
17+
# Linting & Formatting
1718
bundle exec rubocop # Ruby linting
1819
bundle exec rubocop [file_path] # Lint specific file
1920
# Note: yarn format requires local setup, format manually
@@ -23,6 +24,7 @@ cd spec/dummy && foreman start # Start dummy app with webpack
2324
```
2425

2526
### CI Compliance Checklist
27+
2628
- [ ] `bundle exec rubocop` passes with no offenses
2729
- [ ] All RSpec tests pass
2830
- [ ] No trailing whitespace
@@ -32,23 +34,27 @@ cd spec/dummy && foreman start # Start dummy app with webpack
3234
## Development Patterns for AI Contributors
3335

3436
### 1. Task Management
37+
3538
Always use TodoWrite tool for multi-step tasks to:
39+
3640
- Track progress transparently
3741
- Show the user what's being worked on
3842
- Ensure no steps are forgotten
3943
- Mark tasks complete as you finish them
4044

4145
```markdown
4246
Example workflow:
47+
4348
1. Analyze the problem
4449
2. Create test cases
45-
3. Implement the fix
50+
3. Implement the fix
4651
4. Run tests
4752
5. Fix linting issues
4853
6. Update documentation
4954
```
5055

5156
### 2. Test-Driven Development
57+
5258
When fixing bugs or adding features:
5359

5460
1. **Create failing tests first** that reproduce the issue
@@ -57,13 +63,15 @@ When fixing bugs or adding features:
5763
4. **Verify all existing tests still pass**
5864

5965
### 3. File Processing Guidelines
66+
6067
When working with file generation or processing:
6168

6269
- **Filter by extension**: Only process relevant files (e.g., `.js/.jsx/.ts/.tsx` for React components)
6370
- **Validate assumptions**: Don't assume all files in a directory are components
6471
- **Handle edge cases**: CSS modules, config files, etc. should be excluded appropriately
6572

6673
Example from CSS module fix:
74+
6775
```ruby
6876
COMPONENT_EXTENSIONS = /\.(jsx?|tsx?)$/
6977

@@ -77,15 +85,17 @@ end
7785
### Common Fixes
7886

7987
1. **Trailing Whitespace**
88+
8089
```ruby
8190
# Bad
82-
let(:value) { "test" }
83-
84-
# Good
91+
let(:value) { "test" }
92+
93+
# Good
8594
let(:value) { "test" }
8695
```
8796

8897
2. **Line Length (120 chars max)**
98+
8999
```ruby
90100
# Bad
91101
expect { eval(pack_content.gsub(/import.*from.*['"];/, "").gsub(/ReactOnRails\.register.*/, "")) }.not_to raise_error
@@ -97,11 +107,12 @@ end
97107
```
98108

99109
3. **Named Subjects (RSpec)**
110+
100111
```ruby
101112
# Bad
102113
describe "#method_name" do
103114
subject { instance.method_name(arg) }
104-
115+
105116
it "does something" do
106117
expect(subject).to eq "result"
107118
end
@@ -110,14 +121,15 @@ end
110121
# Good
111122
describe "#method_name" do
112123
subject(:method_result) { instance.method_name(arg) }
113-
124+
114125
it "does something" do
115126
expect(method_result).to eq "result"
116127
end
117128
end
118129
```
119130

120131
4. **Security/Eval Violations**
132+
121133
```ruby
122134
# Bad
123135
expect { eval(dangerous_code) }.not_to raise_error
@@ -130,6 +142,7 @@ end
130142
```
131143

132144
### RuboCop Workflow
145+
133146
1. Run `bundle exec rubocop [file]` to see violations
134147
2. Fix violations manually or with auto-correct where safe
135148
3. Re-run to verify fixes
@@ -138,15 +151,16 @@ end
138151
## Testing Best Practices
139152

140153
### Test Structure
154+
141155
```ruby
142156
describe "FeatureName" do
143157
context "when condition A" do
144158
let(:setup) { create_test_condition }
145-
159+
146160
before do
147161
# Setup code
148162
end
149-
163+
150164
it "does expected behavior" do
151165
# Arrange, Act, Assert
152166
end
@@ -155,11 +169,13 @@ end
155169
```
156170

157171
### Test Fixtures
172+
158173
- Create realistic test data that represents edge cases
159174
- Use descriptive names for fixtures and variables
160175
- Clean up after tests (handled by RSpec automatically in most cases)
161176

162177
### CSS Module Testing Example
178+
163179
```ruby
164180
# Create test fixtures
165181
Write.create("ComponentWithCSSModule.module.css", css_content)
@@ -175,6 +191,7 @@ end
175191
## Git & PR Workflow
176192

177193
### Branch Management
194+
178195
```bash
179196
git checkout -b fix/descriptive-name
180197
# Make changes
@@ -189,11 +206,12 @@ git push -u origin fix/descriptive-name
189206
```
190207

191208
### Commit Message Format
209+
192210
```
193211
Brief description of the change
194212
195213
- Detailed bullet points of what changed
196-
- Why the change was needed
214+
- Why the change was needed
197215
- Any breaking changes or considerations
198216
199217
Fixes #issue_number
@@ -204,7 +222,9 @@ Co-Authored-By: Claude <noreply@anthropic.com>
204222
```
205223

206224
### PR Creation
225+
207226
Use `gh pr create` with:
227+
208228
- Clear title referencing the issue
209229
- Comprehensive description with summary and test plan
210230
- Link to the issue being fixed
@@ -213,21 +233,25 @@ Use `gh pr create` with:
213233
## Common Pitfalls & Solutions
214234

215235
### 1. File Path Issues
236+
216237
- Always use absolute paths in tools
217238
- Check current working directory with `pwd`
218239
- Use proper path joining methods
219240

220241
### 2. Test Environment
242+
221243
- Run tests from correct directory (often project root)
222244
- Understand the difference between gem tests vs dummy app tests
223245
- Clean up test artifacts appropriately
224246

225247
### 3. Dependency Management
248+
226249
- Don't assume packages are installed globally
227250
- Use `bundle exec` for Ruby commands
228251
- Verify setup with `bundle && yarn` when needed
229252

230253
### 4. RuboCop Configuration
254+
231255
- Different rules may apply to different directories
232256
- Use `bundle exec rubocop` (not global rubocop)
233257
- Check `.rubocop.yml` files for project-specific rules
@@ -248,7 +272,7 @@ Use `gh pr create` with:
248272
- Ensure fix doesn't break existing functionality
249273
- Follow existing code patterns
250274

251-
4. **Verify Solution**
275+
4. **Verify Solution**
252276
- All new tests pass
253277
- All existing tests still pass
254278
- RuboCop compliance maintained
@@ -257,6 +281,7 @@ Use `gh pr create` with:
257281
## IDE Configuration for AI Context
258282

259283
When analyzing codebases, ignore these directories to avoid confusion:
284+
260285
- `/coverage`, `/tmp`, `/gen-examples`
261286
- `/node_package/lib`, `/node_modules`
262287
- `/spec/dummy/app/assets/webpack`
@@ -266,7 +291,7 @@ When analyzing codebases, ignore these directories to avoid confusion:
266291
## Communication with Human Maintainers
267292

268293
- Be transparent about AI-generated changes
269-
- Explain reasoning behind implementation choices
294+
- Explain reasoning behind implementation choices
270295
- Ask for clarification when requirements are ambiguous
271296
- Provide comprehensive commit messages and PR descriptions
272297
- Include test plans and verification steps
@@ -281,4 +306,4 @@ When analyzing codebases, ignore these directories to avoid confusion:
281306

282307
---
283308

284-
This guide evolves based on AI contributor experiences. Suggest improvements via issues or PRs!
309+
This guide evolves based on AI contributor experiences. Suggest improvements via issues or PRs!

docs/additional-details/migrating-from-react-rails.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,16 @@
33
In this guide, it is assumed that you have upgraded the `react-rails` project to use `shakapacker` version 7. To this end, check out [Shakapacker v7 upgrade guide](https://github.com/shakacode/shakapacker/tree/master/docs/v7_upgrade.md). Upgrading `react-rails` to version 3 can make the migration smoother but it is not required.
44

55
1. Update Deps
6-
76
1. Replace `react-rails` in `Gemfile` with the latest version of `react_on_rails` and run `bundle install`.
87
2. Remove `react_ujs` from `package.json` and run `yarn install`.
98
3. Commit changes!
109

1110
2. Run `rails g react_on_rails:install` but do not commit the change. `react_on_rails` installs node dependencies and also creates sample React component, Rails view/controller, and updates `config/routes.rb`.
1211

1312
3. Adapt the project: Check the changes and carefully accept, reject, or modify them as per your project's needs. Besides changes in `config/shakapacker` or `babel.config` which are project-specific, here are the most noticeable changes to address:
14-
1513
1. Check Webpack config files at `config/webpack/*`. If coming from `react-rails` v3, the changes are minor since you have already made separate configurations for client and server bundles. The most important change here is to notice the different names for the server bundle entry file. You may choose to stick with `server_rendering.js` or use `server-bundle.js` which is the default name in `react_on_rails`. The decision made here affects the other steps.
1614

1715
2. In `app/javascript` directory you may notice some changes.
18-
1916
1. `react_on_rails` by default uses `bundles` directory for the React components. You may choose to rename `components` into `bundles` to follow the convention.
2017

2118
2. `react_on_rails` uses `client-bundle.js` and `server-bundle.js` instead of `application.js` and `server_rendering.js`. There is nothing special about these names. It can be set to use any other name (as mentioned above). If you too choose to follow the new names, consider updating the relevant `javascript_pack_tag` in your Rails views.

docs/getting-started.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ You may need to check [the instructions for installing into an existing Rails ap
3838
```
3939

4040
3. Start the app:
41-
4241
- Run `./bin/dev` for HMR
43-
- Run `./bin/dev-static` for statically created bundles (no HMR)
42+
- Run `./bin/dev static` for statically created bundles (no HMR)
4443

4544
4. Visit http://localhost:3000/hello_world.
4645

docs/guides/streaming-server-rendering.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ You can test your application by running `rails server` and navigating to the ap
119119
When a user visits the page, they'll experience the following sequence:
120120

121121
1. The initial HTML shell is sent immediately, including:
122-
123122
- The page layout
124123
- Any static content (like the `<h1>` and footer)
125124
- Placeholder content for the React component (typically a loading state)
@@ -165,13 +164,11 @@ Streaming SSR is particularly valuable in specific scenarios. Here's when to con
165164
### Ideal Use Cases
166165

167166
1. **Data-Heavy Pages**
168-
169167
- Pages that fetch data from multiple sources
170168
- Dashboard-style layouts where different sections can load independently
171169
- Content that requires heavy processing or computation
172170

173171
2. **Progressive Enhancement**
174-
175172
- When you want users to see and interact with parts of the page while others load
176173
- For improving perceived performance on slower connections
177174
- When different parts of your page have different priority levels

docs/guides/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Then run the server with one of the following options:
134134
```bash
135135
./bin/dev # For HMR
136136
# or
137-
./bin/dev-static # Without HMR, statically creating the bundles
137+
./bin/dev static # Without HMR, statically creating the bundles
138138
```
139139

140140
Visit [http://localhost:3000/hello_world](http://localhost:3000/hello_world) and see your **React On Rails** app running!

docs/guides/upgrading-react-on-rails.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,8 @@ const { output } = webpackConfigLoader(configPath);
238238
For an example of upgrading, see [react-webpack-rails-tutorial/pull/416](https://github.com/shakacode/react-webpack-rails-tutorial/pull/416).
239239

240240
- Breaking Configuration Changes
241-
242241
1. Added `config.node_modules_location` which defaults to `""` if Webpacker is installed. You may want to set this to `'client'` in `config/initializers/react_on_rails.rb` to keep your `node_modules` inside the `/client` directory.
243242
2. Renamed
244-
245243
- config.npm_build_test_command ==> config.build_test_command
246244
- config.npm_build_production_command ==> config.build_production_command
247245

@@ -253,7 +251,6 @@ gem "webpacker"
253251

254252
- Update for the renaming in the `WebpackConfigLoader` in your Webpack configuration.
255253
You will need to rename the following object properties:
256-
257254
- webpackOutputPath ==> output.path
258255
- webpackPublicOutputDir ==> output.publicPath
259256
- hotReloadingUrl ==> output.publicPathWithHost
@@ -265,7 +262,6 @@ gem "webpacker"
265262
- devBuild ==> Use `const devBuild = process.env.NODE_ENV !== 'production';`
266263

267264
- Edit your Webpack.config files:
268-
269265
- Change your Webpack output to be like this. **Be sure to have the hash or chunkhash in the filename,** unless the bundle is server side.:
270266

271267
```
@@ -295,7 +291,6 @@ gem "webpacker"
295291
```
296292
297293
- Find your `webpacker_lite.yml` and rename it to `webpacker.yml`
298-
299294
- Consider copying a default webpacker.yml setup such as https://github.com/shakacode/react-on-rails-v9-rc-generator/blob/master/config/webpacker.yml
300295
- If you are not using the webpacker Webpack setup, be sure to put in `compile: false` in the `default` section.
301296
- Alternately, if you are updating from webpacker_lite, you can manually change these:

docs/release-notes/15.0.0.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ _The image above demonstrates the dramatic performance improvement:_
5757
- The `generated_component_packs_loading_strategy` defaults to `:async` for Shakapacker ≥ 8.2.0 and `:sync` for Shakapacker < 8.2.0.
5858
- The `force_load` configuration now defaults to `true`.
5959
- The new default values of `generated_component_packs_loading_strategy: :async` and `force_load: true` work together to optimize component hydration. Components now hydrate as soon as their code and server-rendered HTML are available, without waiting for the full page to load. This parallel processing significantly improves time-to-interactive by eliminating the traditional waterfall of waiting for page load before beginning hydration (It's critical for streamed HTML).
60-
6160
- The previous need for deferring scripts to prevent race conditions has been eliminated due to improved hydration handling. Making scripts not defer is critical to execute the hydration scripts early before the page is fully loaded.
6261
- The `force_load` configuration makes `react-on-rails` hydrate components immediately as soon as their server-rendered HTML reaches the client, without waiting for the full page load.
6362
- If you want to keep the previous behavior, you can set `generated_component_packs_loading_strategy: :defer` or `force_load: false` in your `config/initializers/react_on_rails.rb` file.
@@ -66,7 +65,6 @@ _The image above demonstrates the dramatic performance improvement:_
6665
- You can override this behavior for individual Redux stores by calling the `redux_store` helper with `force_load: false`, same as `react_component`.
6766

6867
- `ReactOnRails.reactOnRailsPageLoaded()` is now an async function:
69-
7068
- If you manually call this function to ensure components are hydrated (e.g., with async script loading), you must now await the promise it returns:
7169

7270
```js

0 commit comments

Comments
 (0)