react-on-rails is the client-side JavaScript package designed to integrate React applications seamlessly within a Ruby on Rails environment, specifically leveraging the Rails asset pipeline (e.g., Shakapacker, Webpack, Rspack). Currently at stable version 16.6.0, the library facilitates component registration, client-side hydration, and server-side rendering (SSR) of React components. It maintains an active release cadence with frequent updates and bug fixes, indicated by its minor and patch releases. Its primary differentiator is its tight coupling with the `react_on_rails` Ruby gem, providing a robust, opinionated solution for isomorphic React development in Rails. This includes essential functionalities like connecting React components to Redux stores and supporting advanced features such as server-side rendering, with specific capabilities for TanStack Router via its `react-on-rails-pro` offering. It's a foundational component for modern React-in-Rails development.
npm install react-on-railsVerified import paths — ran on the pinned version, not inferred.
This quickstart registers a simple 'HelloWorld' React component with `react-on-rails`, making it available for rendering within Rails views using the `react_component` helper, supporting both client-side hydration and server-side rendering.
Remove all references to `immediate_hydration` from your React on Rails initializer, helper calls (`react_component`), and Redux store configurations. Any existing usage will lead to errors.
Ensure `gem 'react_on_rails'` is present in your `Gemfile` and run `bundle install`, then typically `rails generate react_on_rails:install` to set up the Rails-side integration.
If using React on Rails Pro, install `npm install react-on-rails-pro` (or `yarn add react-on-rails-pro`) and ensure `gem 'react_on_rails_pro'` is in your `Gemfile`.
Use `rails generate react_on_rails:install` to ensure correct bundler configuration. For troubleshooting, run `react_on_rails:doctor` to diagnose common setup problems, especially with TypeScript or different bundlers.
Ensure your entry file (e.g., `application.js` or `application.ts`) has `import ReactOnRails from 'react-on-rails';` at the top. Verify your asset pipeline is compiling and including this entry file.
Remove `immediate_hydration` from your `react_on_rails` initializer (e.g., `config/initializers/react_on_rails.rb`), from any `react_component` helper calls, and from `redux_store` configurations. This option is no longer supported.
Ensure `ReactOnRails.register({ MyComponent });` is called in your main JavaScript entry file after `MyComponent` has been imported. Double-check the component name for exact matching.Verify that your server bundle (e.g., `server-bundle.js` or `server-bundle.ts`) exists, compiles without errors, and is correctly referenced in your `react_on_rails` configuration. Check `log/react_on_rails.log` for more specific errors during SSR.