talira

React on Rails

Integration of React + Webpack + Rails including server-side rendering of React

open coreMITself-hostablefree

React on Rails puts React components into Rails views with a react_component view helper, passing props from the controller, with server-side rendering, hot reloading and automatic bundle generation. It builds the JavaScript with Shakapacker (webpack or Rspack), so a team keeps one Rails app instead of splitting off a separate frontend and API. The open source gem renders on the server through ExecJS; React on Rails Pro, a paid edition from the same maintainers, adds a Node.js rendering server, streaming SSR, React Server Components, fragment and bundle caching, code splitting and TanStack Router SSR. ShakaCode maintains both.

Problems it solves

  • use React components inside my existing Rails views without rewriting the app as a SPA
  • server-render React in Rails so the page shows content before JavaScript loads
  • pass data from a Rails controller straight into a React component as props
  • I don't want to maintain a separate Next.js frontend and a Rails API
  • set up webpack for a Rails app with hot reloading for React
  • add a complex interactive editor to a few pages of an otherwise server-rendered Rails app
  • stream server-rendered React from Rails for faster first paint
  • use React Server Components with a Rails backend
  • react-rails is in maintenance mode and I need a supported way to mix React and Rails
  • split my React bundle per page in a Rails app so each page loads only what it needs

Features

  • react_component view helper
  • props from Rails controllers
  • server-side rendering (ExecJS in OSS)
  • hot reloading
  • automatic bundle generation
  • Shakapacker with webpack or Rspack
  • generator and create-react-on-rails-app
  • react_on_rails:doctor diagnostics
  • Pro: Node renderer, streaming SSR, React Server Components, fragment and bundle caching, code splitting, TanStack Router SSR

Ways to run it

React on Rails

You run it, MIT

free

Not included

  • Node.js renderer
  • streaming SSR
  • React Server Components
  • fragment and bundle caching
  • code splitting / Loadable Components
  • TanStack Router SSR

You arrange

  • a Rails app with Shakapacker (webpack or Rspack)
  • Node.js 18+ and a JavaScript package manager for builds

Self-hosting docs

React on Rails Pro

You run it, under a commercial licence

free in development, test, CI and staging, and in production for organizations under 10 people, $1M revenue in the last twelve months and $1M raised ever; otherwise ShakaStack Pro, $1,800 per year per organization

Only in this edition

  • Node.js renderer for server rendering
  • streaming SSR
  • React Server Components
  • fragment caching
  • bundle caching
  • code splitting / Loadable Components
  • TanStack Router SSR
  • with ShakaStack Pro: Slack support from the maintainers, ShakaPerf and Inertia Rails SSR Cache

You arrange

  • a Node.js rendering server (the react-on-rails-pro-node-renderer package) running alongside Rails

Pricing

Capabilities

Has a command line toolplan not known

Alternatives

The same job

These do what React on Rails does.

  1. Stimulus A modest JavaScript framework for the HTML you already have
  2. Hotwire HTML over the wire
  3. Inertia.js Build frontend experiences with the backend you love

Compare React on Rails with the top 3