Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .claude/settings.local.json
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file should not be in the repo. I'll remove in a separate commit.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"permissions": {
"allow": [
"Bash(find:*)",
"Bash(git add:*)",
"Bash(git push:*)",
"Bash(rails new:*)",
"Bash(bundle:*)",
"Bash(rails:*)",
"Bash(git init:*)",
"Bash(git commit:*)",
"Bash(npm install:*)",
"Bash(bin/shakapacker:*)",
"Bash(git checkout:*)",
"Bash(git rebase:*)",
"WebFetch(domain:github.com)",
"Bash(yarn run lint)",
"Bash(yarn run prettier:*)",
"Bash(test:*)",
"Bash(rake lint)",
"Bash(yarn run:*)",
"WebFetch(domain:vite-ruby.netlify.app)",
"WebSearch",
"Bash(gem install:*)",
"Bash(gem search:*)",
"Bash(git reset:*)",
"Read(//Users/justin/shakacode/react-on-rails/**)",
"Bash(./bin/dev)",
"Bash(node:*)",
"Bash(git cherry-pick:*)"
],
"deny": [],
"ask": []
}
}
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ yalc.lock
# Generated by ROR FS-based Registry
generated

# Claude Code local settings
.claude/settings.local.json
# Test applications directory
/test-apps/
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ spec/dummy/public
*.yaml
# Intentionally invalid
spec/react_on_rails/fixtures/i18n/locales_symbols/

# Internal documentation - ignore formatting
CLAUDE.md
docs/contributor-info/coding-agents-guide.md
231 changes: 231 additions & 0 deletions AI_AGENT_INSTRUCTIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
# πŸ€– AI Agent Instructions: React on Rails Setup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

🧩 Analysis chain

Fix Prettier/markdownlint failures for this file.

CI reports Prettier issues; run:


🏁 Script executed:

#!/bin/bash
npx prettier --write AI_AGENT_INSTRUCTIONS.md
npx markdownlint-cli2 AI_AGENT_INSTRUCTIONS.md

Length of output: 1058


Fix markdownlint failures in AI_AGENT_INSTRUCTIONS.md (MD013, MD040)

Prettier ran but markdownlint still reports 8 errors β€” wrap long lines to ≀80 chars and add language specifiers to fenced code blocks.

  • Line 3: MD013 line-length (100) β€” wrap to ≀80.
  • Line 18: MD013 line-length (151) β€” wrap to ≀80.
  • Line 31: MD040 fenced-code-language β€” add language (e.g., ```bash).
  • Line 37: MD040 fenced-code-language β€” add language.
  • Line 64: MD013 line-length (100) β€” wrap to ≀80.
  • Line 217: MD040 fenced-code-language β€” add language.
  • Line 234: MD013 line-length (85) β€” wrap to ≀80.
  • Line 240: MD013 line-length (120) β€” wrap to ≀80.

Re-run verification after fixes:

npx prettier --write AI_AGENT_INSTRUCTIONS.md && npx markdownlint-cli2 AI_AGENT_INSTRUCTIONS.md
🧰 Tools
πŸͺ› GitHub Actions: Lint JS and Ruby

[error] 1-1: Prettier formatting issues detected. Run 'prettier --write' to fix.

πŸ€– Prompt for AI Agents
In AI_AGENT_INSTRUCTIONS.md around lines 1 to 240, several markdownlint issues
need fixing: wrap the long lines at 3, 18, 64, 234, and 240 to ≀80 characters
each (break sentences or wrap lists so no line exceeds 80 chars), and add
language specifiers to the fenced code blocks at lines 31, 37, and 217 (e.g.,
change ``` to ```bash or appropriate language). After applying those edits, run
the provided verification command to ensure all MD013 and MD040 errors are
resolved: npx prettier --write AI_AGENT_INSTRUCTIONS.md && npx markdownlint-cli2
AI_AGENT_INSTRUCTIONS.md


*Super concise, copy-paste instructions for AI agents to set up React on Rails in common scenarios.*

## πŸ” **Before Starting: Check Current Versions**

```bash
# Get latest available versions (recommended approach)
gem search react_on_rails --remote
gem search shakapacker --remote

# Or use specific versions from these commands in your Gemfile:
# Latest stable versions as of Jan 2025:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Latest stable versions as of Jan 2025:
# Latest stable versions as of August 2025:

# react_on_rails ~> 15.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't 15.0 yanked?

# shakapacker ~> 8.3
```
Comment on lines +12 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Update pinned versions to v16 series.

This PR targets 16.0.1-rc.2; docs still mention β€œLatest stable as of Jan 2025” and react_on_rails ~> 15.0. Recommend bumping to ~> 16.0 or remove the pinned example and say β€œbundle add react_on_rails --strict”.

-# Latest stable versions as of Jan 2025:
-# react_on_rails ~> 15.0
-# shakapacker ~> 8.3
+# Recommended constraint (Sep 2025):
+# react_on_rails ~> 16.0
+# shakapacker ~> 8.3
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Or use specific versions from these commands in your Gemfile:
# Latest stable versions as of Jan 2025:
# react_on_rails ~> 15.0
# shakapacker ~> 8.3
```
# Or use specific versions from these commands in your Gemfile:
# Recommended constraint (Sep 2025):
# react_on_rails ~> 16.0
# shakapacker ~> 8.3
πŸ€– Prompt for AI Agents
AI_AGENT_INSTRUCTIONS.md around lines 12 to 16: the docs still show a pinned
example using react_on_rails ~> 15.0 and reference "Latest stable as of Jan
2025" while the PR targets v16 (16.0.1-rc.2); update the text to reference the
v16 series by changing the example to ~> 16.0 (or remove the pinned example
entirely and replace with the suggested guidance "bundle add react_on_rails
--strict"), and update or remove the dated "Latest stable as of Jan 2025"
phrasing so it reflects the v16 recommendation.


**⚠️ Version Flexibility:** These instructions use `~> X.Y` which allows patch updates. Always check for latest versions before starting a new project.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually need them to be exactly the same.


## 🚨 **CRITICAL: Installation Order Matters**

**ALWAYS install Shakapacker FIRST, then React on Rails. Here's why:**

1. **React on Rails generator requires `package.json`** to add JavaScript dependencies
2. **Rails with `--skip-javascript` doesn't create `package.json`**
3. **Shakapacker creates `package.json`** and JavaScript tooling foundation
4. **Wrong order = "package.json not found" error**

**βœ… Correct Order:**
```
Shakapacker β†’ package.json created β†’ React on Rails β†’ success
```

**❌ Wrong Order:**
```
React on Rails β†’ no package.json β†’ ERROR: package.json not found
```

---

## πŸ†• Scenario 1: New Rails App with React on Rails

```bash
# Create new Rails app
rails new myapp --skip-javascript --database=postgresql
cd myapp

# STEP 1: Add Shakapacker first (creates package.json)
echo 'gem "shakapacker", "~> 8.3"' >> Gemfile
bundle install
bundle exec rails shakapacker:install

# STEP 2: Add React on Rails (requires package.json to exist)
echo 'gem "react_on_rails", "~> 15.0"' >> Gemfile
bundle install
rails generate react_on_rails:install

# Start development servers
bin/dev
```
Comment on lines +43 to +60
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ› οΈ Refactor suggestion

Include npm/yarn install before starting dev servers.

Generators add JS deps; without install, bin/dev often fails on a clean machine.

 rails generate react_on_rails:install
 
 # Start development servers
-bin/dev
+npm install # or: yarn install
+bin/dev
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
```bash
# Create new Rails app
rails new myapp --skip-javascript --database=postgresql
cd myapp
# STEP 1: Add Shakapacker first (creates package.json)
echo 'gem "shakapacker", "~> 8.3"' >> Gemfile
bundle install
bundle exec rails shakapacker:install
# STEP 2: Add React on Rails (requires package.json to exist)
echo 'gem "react_on_rails", "~> 15.0"' >> Gemfile
bundle install
rails generate react_on_rails:install
# Start development servers
bin/dev
```
rails generate react_on_rails:install
# Start development servers
npm install # or: yarn install
bin/dev
πŸ€– Prompt for AI Agents
In AI_AGENT_INSTRUCTIONS.md around lines 43 to 60, the shell steps start the dev
server without installing JS dependencies produced by the generators; update the
sequence to run the JS package install after running shakapacker and
react_on_rails generators and before running bin/dev β€” e.g., run yarn install
(or npm install/pnpm install depending on project) right after the generators
complete so node_modules are present before starting the dev servers.


**βœ… Success Check:** Visit `http://localhost:3000/hello_world` β†’ Should see "Hello World" from React

**πŸ“ Generated Files:**
- `app/javascript/bundles/HelloWorld/components/HelloWorld.jsx`
- `app/controllers/hello_world_controller.rb`
- `app/views/hello_world/index.html.erb`

---

## πŸ”„ Scenario 2: Add React on Rails to Existing Rails App

```bash
# Navigate to existing Rails app root
cd /path/to/existing/app

# STEP 1: Add Shakapacker first (creates package.json if missing)
echo 'gem "shakapacker", "~> 8.3"' >> Gemfile
bundle install

# Check if package.json exists, create if missing
if [ ! -f "package.json" ]; then
bundle exec rails shakapacker:install
fi

# STEP 2: Add React on Rails (requires package.json to exist)
echo 'gem "react_on_rails", "~> 15.0"' >> Gemfile
bundle install
rails generate react_on_rails:install --ignore-existing-files

Comment on lines +86 to +90
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ’‘ Verification agent

🧩 Analysis chain

Verify generator flag support (--ignore-existing-files).

I’m not sure this flag exists for react_on_rails:install. If unsupported, the command will fail.

Run a quick check or update to a supported flag, e.g., remove it if unnecessary:

-rails generate react_on_rails:install --ignore-existing-files
+rails generate react_on_rails:install

🌐 Web query:

What are the supported options for `rails generate react_on_rails:install` in React on Rails 15.x?

πŸ’‘ Result:

Supported generator options (rails generate react_on_rails:install) in React on Rails 15.x:

  • --redux / --no-redux (alias -R) β€” install Redux example and related gems. [1][2]
  • --server-rendering / --no-server-rendering (alias -S) β€” add server‑side rendering files/config. [2]
  • --skip-js-linters / --no-skip-js-linters (alias -j) β€” skip installing JS linting files. [2]
  • --ruby-linters / --no-ruby-linters (alias -L) β€” install Ruby linting files/tasks/configs. [2]
  • --heroku-deployment / --no-heroku-deployment (alias -H) β€” add files for Heroku deployment. [2]
  • --skip-bootstrap / --no-skip-bootstrap (alias -b) β€” skip Bootstrap integration. [2]
  • --ignore-warnings / --no-ignore-warnings β€” skip generator warnings. [1]
  • Common runtime flags: --force (-f), --pretend (-p), --quiet (-q), --skip (-s). [1][2]

Sources: React on Rails generator docs and package docs. [1] [2]

References
[1] Generator Details β€” React on Rails docs. (shakacode.gitbooks.io)
[2] react_on_rails generator options (package docs / npm). (npmjs.com)

Citations:


Drop unsupported --ignore-existing-files flag
The react_on_rails:install generator in React on Rails 15.x does not support --ignore-existing-files (use --ignore-warnings to suppress warnings). Update to:

-rails generate react_on_rails:install --ignore-existing-files
+rails generate react_on_rails:install
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# STEP 2: Add React on Rails (requires package.json to exist)
echo 'gem "react_on_rails", "~> 15.0"' >> Gemfile
bundle install
rails generate react_on_rails:install --ignore-existing-files
# STEP 2: Add React on Rails (requires package.json to exist)
echo 'gem "react_on_rails", "~> 15.0"' >> Gemfile
bundle install
rails generate react_on_rails:install
πŸ€– Prompt for AI Agents
In AI_AGENT_INSTRUCTIONS.md around lines 86 to 90, the react_on_rails install
command uses the unsupported --ignore-existing-files flag; replace that flag
with --ignore-warnings (or remove it) so the generator call works with React on
Rails 15.x and suppresses warnings if desired.

# Add React component to existing view
# Replace <view-name> with your actual view file
cat >> app/views/<view-name>/<action>.html.erb << 'EOF'

<%= react_component("HelloWorld", props: { name: "World" }) %>
EOF

# Start development
bin/dev
```

**⚠️ Pre-flight Checks:**
- Rails app has `bin/dev` or similar dev script
- Shakapacker will create `package.json` if it doesn't exist
- No existing React setup conflicts

**βœ… Success Check:** React component renders in your chosen view

---

## ⚑ Scenario 3: Convert Vite-Ruby to React on Rails

```bash
# Navigate to app root
cd /path/to/vite/ruby/app

# Remove Vite-Ruby gems from Gemfile
sed -i.bak '/gem.*vite_rails/d' Gemfile
sed -i.bak '/gem.*vite_ruby/d' Gemfile

# Backup existing Vite config
mv vite.config.* vite.config.backup 2>/dev/null || true

# Remove Vite-specific files
rm -rf config/vite.json
rm -rf bin/vite*

# STEP 1: Add Shakapacker first (creates package.json)
echo 'gem "shakapacker", "~> 8.3"' >> Gemfile
bundle install
bundle exec rails shakapacker:install --force

# STEP 2: Add React on Rails (requires package.json to exist)
echo 'gem "react_on_rails", "~> 15.0"' >> Gemfile
bundle install
rails generate react_on_rails:install --force

# Migrate existing React components
# Move components from app/frontend/entrypoints/ to app/javascript/bundles/
mkdir -p app/javascript/bundles/Components
find app/frontend -name "*.jsx" -o -name "*.tsx" | while read file; do
basename=$(basename "$file")
cp "$file" "app/javascript/bundles/Components/$basename"
done

# Update component registrations in app/javascript/packs/hello-world-bundle.js
echo "// Register your existing components here"
echo "// import YourComponent from '../bundles/Components/YourComponent';"
echo "// ReactOnRails.register({ YourComponent });"

# Clean up old Vite files
rm -rf app/frontend
rm -rf public/vite*

# Update views to use React on Rails helpers
# Replace vite_javascript_tag with javascript_pack_tag
# Replace vite_stylesheet_tag with stylesheet_pack_tag

# Install dependencies
yarn install

# Start development
bin/dev
```
Comment on lines +111 to +164
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ› οΈ Refactor suggestion

Fix find(1) OR precedence and restrict to files; standardize package install.

The find expression needs grouping; otherwise matches can be inconsistent. Also, prefer npm (or explicitly note yarn alternative) for consistency with the rest of the doc.

-find app/frontend -name "*.jsx" -o -name "*.tsx" | while read file; do
+find app/frontend \( -name "*.jsx" -o -name "*.tsx" \) -type f | while read file; do
     basename=$(basename "$file")
     cp "$file" "app/javascript/bundles/Components/$basename"
 done
@@
-# Install dependencies
-yarn install
+# Install dependencies
+npm install # or: yarn install
πŸ€– Prompt for AI Agents
In AI_AGENT_INSTRUCTIONS.md around lines 111 to 164 the find command used to
copy JSX/TSX components lacks grouped OR precedence and doesn't restrict results
to files, which can yield unexpected matches; update the find invocation to
group the name tests and add -type f (e.g. use find app/frontend \( -name
"*.jsx" -o -name "*.tsx" \) -type f ...) and standardize the package manager
step by replacing the loose "yarn install" instruction with a single explicit
command (prefer npm install, or state "npm install (or yarn install if you
prefer)") so the doc is consistent.


**πŸ”§ Manual Steps Required:**
1. **Update views**: Replace `vite_javascript_tag` with `javascript_pack_tag "hello-world-bundle"`
2. **Register components**: Add your components to `app/javascript/packs/hello-world-bundle.js`
3. **Update imports**: Change relative paths if needed

**βœ… Success Check:**
- `bin/dev` starts without Vite errors
- React components render using `<%= react_component("YourComponent") %>`

---

## πŸ› οΈ Common Troubleshooting Commands

```bash
# Check current versions and compatibility
bundle info react_on_rails shakapacker
rails --version
ruby --version
node --version

# Check React on Rails installation
rails runner "puts ReactOnRails::VERSION"

# Verify Shakapacker setup
bin/shakapacker --version

# Clear cache if components not updating
rm -rf tmp/cache public/packs
rails assets:clobber

# Check component registration
rails runner "puts ReactOnRails.configuration.components_subdirectory"

# Restart with clean build
pkill -f "bin/shakapacker-dev-server"
rm -rf public/packs-test
bin/dev
```

---

## πŸ“‹ Quick Reference

### Essential Files Structure
```
app/
β”œβ”€β”€ controllers/hello_world_controller.rb
β”œβ”€β”€ views/hello_world/index.html.erb
└── javascript/
β”œβ”€β”€ bundles/HelloWorld/components/HelloWorld.jsx
└── packs/hello-world-bundle.js
```

### Key Commands
- **Development**: `bin/dev` (starts Rails + Shakapacker)
- **Generate**: `rails generate react_on_rails:install`
- **Component**: `<%= react_component("ComponentName", props: {}) %>`

### Version Requirements
- Rails 7+ (Rails 8 supported), Ruby 3.0+ (Ruby 3.2+ for Rails 8), Node 20+ LTS, Yarn
- react_on_rails ~> 15.0+, shakapacker ~> 8.3+
- **Note**: Use `bundle info react_on_rails` to check latest available version

---

*πŸ’‘ **Pro Tip for AI Agents**: Always run `bin/dev` to test setup, and check browser console for any JavaScript errors.*
Loading