Introducing a new way to review your PRs.

Read the announcement

shakacode / react-webpack-rails-tutorial

Legacy full-app React on Rails tutorial repo and live demo. See reactonrails.com/examples for current maintained demos.

View on GitHub

16 documents · Updated Nov 4, 2026

docs / development-runtime

Development runtime orchestration

The development runtime is a group of local processes that lets Rails serve pages while ReScript and JavaScript assets rebuild in the background. It also keeps the Node renderer and Redis available so server-rendered React, React Server Components, and realtime features use the same boundaries as the full application.

Runtime topology

Rails is the request entry point on port 3000 in the normal development mode. Thruster starts in front of Puma and forwards application requests while the client asset server supplies development bundles. The Node renderer serves React rendering requests on port 3800. Redis is a local support service for Action Cable and is started by the static profiles rather than by the HMR profile.

The following diagram shows how local requests and source changes move through the runtime.

flowchart LR
  Browser[Browser] --> Thruster[Thruster / Rails :3000]
  Browser -. HMR assets .-> ClientDev[Client asset server :3035]
  Thruster -->|React SSR or RSC| Renderer[Node renderer :3800]
  Rails[Rails application] -->|Action Cable| Redis[Redis :6379]
  ReScript[ReScript watcher] --> ClientBuild[Generated ReScript]
  ClientBuild --> ClientDev
  ClientBuild --> SSRWatch[SSR bundle watcher]
  ClientBuild --> RSCWatch[RSC bundle watcher]
  SSRWatch --> Renderer
  RSCWatch --> Renderer

The HMR profile separates the three JavaScript targets so a browser change, an SSR change, or an RSC change can rebuild without rebuilding unrelated targets. The client target runs in the development asset server. The SSR and RSC targets write bundles that the Node renderer loads.

References: Procfile.dev• L8-17 config/shakapacker.yml• L34-63 config/…/react_on_rails_pro.rb• L7-29 config/cable.yml• L1-8

Startup commands

bin/dev is the normal entry point for local development. Before it starts the selected process profile, it builds the ReScript source and generates the locale JavaScript files. This order gives the asset watchers the generated inputs they need at startup. The matching package scripts provide the ReScript build and watch commands used by this startup path. The project requires Node 22 or newer and pins Yarn to 1.22.22 for these commands.

CommandRuntime profileMain use
bin/devProcfile.devHMR with client, SSR, and RSC watchers
bin/dev staticProcfile.dev-static-assetsStatic development assets with a watcher
bin/dev prodProcfile.dev-prod-assetsProduction-like asset serving on a separate Rails port
bin/dev-staticStatic mode forced through the development server managerA short command when HMR is not useful
bundle exec foreman start -f Procfile.devDirect HMR profileLow-level process profile invocation
yarn node-rendererNode renderer onlyDirectly start the React rendering service

Use bin/dev when possible because a direct Foreman command does not run the pre-start ReScript and locale work performed by the script. The profile manager starts each process from the selected Procfile and gives each process its own log stream. The runtime uses Puma, Thruster, Redis, and Foreman through the Ruby dependencies declared in Gemfile.

References: bin/dev• L10-25 bin/dev• L30-70 bin/dev-static• L4-19 Procfile.dev-static-assets• L1-10 Procfile.dev-prod-assets• L1-10 Gemfile• L17-19 Gemfile• L35 Gemfile• L68-70 package.json• L5-7 package.json• L19-34 package.json• L181-182

Process roles

Each process has one narrow role in the local system. Together they turn source changes into browser assets and renderer bundles while Rails remains available for page requests.

ProcessRoleOutput or boundary
rescriptWatches ReScript source and creates JavaScript inputs.Generated ReScript files used by the asset builds
rails or webRuns the Rails application through Thruster.HTTP requests on port 3000, or port 3001 in the production-assets profile
wp-clientRuns the client development server with HMR.Browser assets and live module updates
wp-serverWatches the server bundle.SSR code consumed by the Node renderer
wp-rscWatches the RSC bundle.React Server Components payload code consumed by the Node renderer
node-rendererRuns the React on Rails Pro Node rendering service.SSR and RSC responses on port 3800
redisRuns the local Redis service in static profiles.Action Cable backing store on port 6379
rspackRebuilds static assets after source changes.Files served from the Rails public asset path

The client, SSR, and RSC watchers use one bundler configuration with separate target selection. The client development server selects the client bundle by default. SERVER_BUNDLE_ONLY=yes selects SSR, and RSC_BUNDLE_ONLY=yes selects RSC.

References: Procfile.dev• L8-17 Procfile.dev-static-assets• L2-10 Procfile.dev-prod-assets• L2-10 config/…/webpackConfig.js• L16-34 renderer/node-renderer.js• L31-59 Gemfile• L9 Gemfile• L19 Gemfile• L35 package.json• L23-34

Asset serving modes

Development offers two asset paths because fast browser feedback and stable files on disk serve different needs. HMR keeps client modules in the development asset server, while static profiles rebuild files into the Rails public asset path.

Hot module replacement

The default profile uses a client development server with HMR and separate watchers for SSR and RSC. The development server listens on port 3035 in the Shakapacker settings, while Rails continues to receive application requests on port 3000.

The client asset server is the right choice for rapid browser work. Changes to server-rendered or RSC code still depend on their matching watcher and the Node renderer process.

References: Procfile.dev• L10-17 config/shakapacker.yml• L34-63 config/…/development.js• L4-10

Static asset builds

The static profiles run Rails, Redis, and one asset watcher. The watcher first generates locale files, clears the existing public packs, and then rebuilds changed assets. Procfile.dev-static adds a short wait before that work so preceding ReScript output has time to appear when the profile is started directly.

The production-assets profile uses Rails port 3001. This lets it run beside the normal development profile when a developer needs to compare static or production-like assets with HMR assets.

References: Procfile.dev-static• L2-11 Procfile.dev-static-assets• L2-10 Procfile.dev-prod-assets• L2-10 config/puma.rb• L29-39

Cross-process contracts

Rails and the Node renderer must agree on the renderer URL and password. Local defaults point Rails to http://localhost:3800 and use the same development password on both sides. Production must provide an explicit password.

The renderer loads the changing SSR and RSC bundles from its bundle cache path. Its default host is localhost, its default port is 3800, and its runtime settings keep timers and async logs working for React Server Components. These settings make the renderer a live part of the development loop rather than a one-time build step.

Redis is a separate local service for the Redis Action Cable adapter. If a profile does not start Redis, a system Redis service must already be running before features that use Action Cable are exercised.

References: config/…/react_on_rails_pro.rb• L7-29 renderer/node-renderer.js• L5-10 renderer/node-renderer.js• L31-56 config/cable.yml• L1-8 Gemfile• L35 package.json• L81-87

Change checklist

When these files or sections are changed, remember to consider these:

  • If the ReScript or locale build order changes, check that both bin/dev and the static asset profiles still create generated inputs before their watchers start.
  • If a bundle target or entry changes, keep the SERVER_BUNDLE_ONLY and RSC_BUNDLE_ONLY process settings aligned with the Rails renderer settings.
  • If the renderer host, port, or password changes, update both the Rails initializer and the Node renderer process contract.
  • If the development asset server port changes, update the Shakapacker dev-server setting and any browser or proxy entry point that directs requests to it.
  • If Redis connection settings change, keep the Action Cable URL and the profile that starts Redis consistent.
  • If the supported Node or Yarn version changes, keep the package engine, package-manager field, and runtime scripts aligned.

Important failure modes

TriggerConsequenceGuard
Starting the Procfile directly without the required generated ReScript or locale filesA watcher can start with missing inputs or stale generated assets.Use bin/dev, or run the same pre-start build steps first.
Starting Rails without the Node rendererReact server rendering fails because Rails is configured not to fall back to ExecJS.Start node-renderer with the selected SSR and RSC watchers.
Using different renderer passwords in Rails and NodeRails cannot authenticate its renderer requests.Keep RENDERER_PASSWORD shared, or use the matching local default on both sides.
Running Action Cable features without Redis on port 6379Redis-backed cable operations cannot connect.Start the profile's Redis process or run a local Redis service.
Clearing public packs while relying on static assetsRails can serve missing packs until the watcher completes a new build.Wait for the static watcher to finish its first build before loading the page.
Running the runtime with an unsupported Node or Yarn versionReScript or asset commands can fail before the process group is ready.Use the versions declared in package.json.

Key files

FileWhy to read it
bin/devDefines the supported entry point and the pre-start generation work.
Procfile.devShows the complete HMR process topology.
Procfile.dev-static-assetsShows the normal static asset profile with Rails, Redis, and a watcher.
Procfile.dev-prod-assetsShows the production-assets development variant and its separate Rails port.
config/shakapacker.ymlDefines the development asset server and its HMR behavior.
config/…/webpackConfig.jsExplains how client, SSR, and RSC watcher processes select their targets.
renderer/node-renderer.jsDefines the local Node rendering service boundary and defaults.
config/…/react_on_rails_pro.rbDefines how Rails reaches and authenticates the renderer.
config/cable.ymlDefines the Redis-backed Action Cable connection used by local runtime features.
GemfileDeclares the Ruby services and process manager that support the local runtime.
package.jsonDeclares the Node and Yarn versions and the scripts that build or watch ReScript and runtime assets.

For the asset build model, see JavaScript and asset build pipeline. For the Rails-to-Node rendering boundary, see Node server rendering. For the ReScript example and its generated-code lifecycle, see ReScript comment demo. For the commands that build assets before validation, see Automated validation.