WARP.md
This file provides guidance to WARP (warp.dev) when working with code in this repository.
React on Rails is a Ruby gem and NPM package that seamlessly integrates React components into Rails applications with server-side rendering, hot module replacement, and automatic bundle optimization. This is a dual-package project maintaining both a Ruby gem (for Rails integration) and an NPM package (for React client-side functionality).
# Initial setup for gem development
bundle && pnpm install -r
# Full setup including examples
bundle && pnpm install -r && rake shakapacker_examples:gen_all && rake node_package && rake
# Install git hooks (automatic on setup)
bundle exec lefthook install
# All tests (excluding examples) - recommended for local development
rake all_but_examples
# Run specific test suites
bundle exec rspec # All Ruby tests from project root
rake run_rspec:gem # Top-level gem tests only
rake run_rspec:dummy # Dummy app tests with turbolinks
rake run_rspec:dummy_no_turbolinks # Dummy app tests without turbolinks
pnpm run test # JavaScript tests (Jest)
# Run single example test
rake run_rspec:shakapacker_examples_basic
# Test environment diagnosis
rake react_on_rails:doctor
VERBOSE=true rake react_on_rails:doctor # Detailed output
# Auto-fix all violations (RECOMMENDED workflow)
rake autofix # Runs eslint --fix, prettier --write, and rubocop -A
# Manual linting
bundle exec rubocop # Ruby - MUST pass before commit
rake lint # All linters (ESLint + RuboCop)
pnpm run lint # ESLint only
rake lint:rubocop # RuboCop only
# Check formatting without fixing
pnpm start format.listDifferent
# Build NPM package (TypeScript → JavaScript)
pnpm run build # One-time build
pnpm run build-watch # Watch mode for development
# Type checking
pnpm run type-check
cd react_on_rails/spec/dummy
# Start development with HMR
foreman start # Uses Procfile.dev (default)
bin/dev # Alternative
# Other modes
bin/dev static # Static assets
bin/dev prod # Production-like environment
# In react_on_rails directory
pnpm run build
yalc publish
# In test app directory
yalc add react-on-rails
# After making changes (CRITICAL STEP)
cd /path/to/react_on_rails
yalc push # Push updates to all linked apps
cd /path/to/test_app
pnpm install -r # Update dependencies
⚠️ MANDATORY BEFORE EVERY COMMIT:
bundle exec rubocop and fix ALL violationsrake autofix to auto-fix formatting issuesNote: Git hooks (via Lefthook) run automatically and check all changed files (staged + unstaged + untracked).
This project maintains two distinct but integrated packages:
lib/)helper.rb - Rails view helpers (react_component, etc.)server_rendering_pool.rb - Manages Node.js processes for SSRconfiguration.rb - Global configuration managementpacks_generator.rb - Auto-bundling and pack generationengine.rb - Rails engine integrationlib/generators/react_on_rails/node_package/src/)ReactOnRails.ts - Main entry point for client-side functionalityserverRenderReactComponent.ts - Server-side rendering logicclientStartup.ts - Client-side component mountingpro/ - React on Rails Pro features (React Server Components, etc.)react_component helperreact_on_rails gemnode_package/src/ → node_package/lib/)connection_pooljavascript_pack_tags configurationpacks_generator.rb for implementationReactOnRails.register({ ComponentName }) in pack filesauto_load_bundle: true optionreact_on_rails/spec/dummy/)gen-examples/)rake shakapacker_examples:gen_allyalc for local package testing, not npm linkyalc push after changes to see updates in test appspnpm run build or pnpm run build-watchyalc pushrake autofix to fix all lintingbundle exec rubocop and pnpm run lintrake all_but_examples# Create test Rails app
rails new test-app --skip-javascript
cd test-app
echo 'gem "react_on_rails", path: "../react_on_rails"' >> Gemfile
bundle install
# Run generator
./bin/rails generate react_on_rails:install
# Test with yalc for full functionality
cd /path/to/react_on_rails
yalc publish
yalc push
cd /path/to/test-app
pnpm install -r
bin/dev
Prettier is the SOLE authority for non-Ruby files. RuboCop is the SOLE authority for Ruby files.
rake autofixgit add .rake autofixgit add .git rebase --continue or git commitNEVER manually format during conflict resolution - this causes formatting wars.
Remove all trailing whitespace from lines
Break long lines into multiple lines using proper indentation
# Good
subject(:method_result) { instance.method_name(arg) }
# rubocop:disable Security/Eval
# ... code with eval
# rubocop:enable Security/Eval
Exclude these directories to prevent IDE slowdowns:
/coverage, /tmp, /gen-examples/node_package/lib, /node_modules/react_on_rails/spec/dummy/app/assets/webpack/react_on_rails/spec/dummy/log, /react_on_rails/spec/dummy/node_modules, /react_on_rails/spec/dummy/tmp/spec/react_on_rails/dummy-for-generatorspackageManager field in package.jsonyalc push after changesrake react_on_rails:doctorbin/dev kill to stop conflicting processesbundle install and pnpm install -r are currentbundle exec lefthook installbundle exec rubocop before pushingrake autofix to fix most issues automatically.rubocop.yml for project-specific rulesThe project is merging react_on_rails and react_on_rails_pro into a unified monorepo. During this transition:
docs/MONOREPO_MERGER_PLAN_REF.md for details