Skip to content

Commit b038c77

Browse files
justin808claude
andcommitted
Apply React on Rails 16.1.1 generator updates with proper SSR configuration
- Run `bin/rails generate react_on_rails:install` to get proper v16 configuration - Server bundles now output to `ssr-generated` directory (private, not public) - Use new configuration options: - `server_bundle_output_path = "ssr-generated"` - `enforce_private_server_bundles = true` - Update webpack config to output server bundles to private directory - Enable auto component registration with `components_subdirectory` - Fix RSpec configuration syntax error from generator This properly implements the React on Rails 16 pattern where server bundles are kept in a private directory separate from public client assets for security. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent db54f37 commit b038c77

27 files changed

+989
-521
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,7 @@ lib/bs
5353
/lib/ocaml
5454

5555
client/app/bundles/comments/rescript/**/*.bs.js
56+
57+
# Generated React on Rails packs
58+
**/generated/**
59+
ssr-generated

Procfile.dev

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Procfile for development using HMR
22
# You can run these commands in separate shells
3-
rescript: yarn res:dev
4-
redis: redis-server
5-
rails: bin/rails s -p 3000
6-
wp-client: HMR=true RAILS_ENV=development NODE_ENV=development bin/shakapacker-dev-server
7-
wp-server: bundle exec rake react_on_rails:locale && HMR=true SERVER_BUNDLE_ONLY=yes bin/shakapacker --watch
3+
rails: bundle exec rails s -p 3000
4+
wp-client: WEBPACK_SERVE=true bin/shakapacker-dev-server
5+
wp-server: SERVER_BUNDLE_ONLY=yes bin/shakapacker --watch

Procfile.dev-prod-assets

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
# You can run these commands in separate shells
2-
web: bin/rails s -p 3001
3-
redis: redis-server
1+
# Procfile for development with production assets
2+
# Uses production-optimized, precompiled assets with development environment
3+
# Uncomment additional processes as needed for your app
44

5-
# Next line runs a watch process with webpack to compile the changed files.
6-
# When making frequent changes to client side assets, you will prefer building webpack assets
7-
# upon saving rather than when you refresh your browser page.
8-
# Note, if using React on Rails localization you will need to run
9-
# `bundle exec rake react_on_rails:locale` before you run bin/shakapacker
10-
webpack: sh -c 'bundle exec rake react_on_rails:locale && rm -rf public/packs/* || true && bin/shakapacker -w'
5+
rails: bundle exec rails s -p 3001
6+
# sidekiq: bundle exec sidekiq -C config/sidekiq.yml
7+
# redis: redis-server
8+
# mailcatcher: mailcatcher --foreground

Procfile.dev-static-assets

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
1-
# You can run these commands in separate shells
2-
web: bin/rails s -p 3000
3-
redis: redis-server
4-
5-
# Next line runs a watch process with webpack to compile the changed files.
6-
# When making frequent changes to client side assets, you will prefer building webpack assets
7-
# upon saving rather than when you refresh your browser page.
8-
# Note, if using React on Rails localization you will need to run
9-
# `bundle exec rake react_on_rails:locale` before you run bin/shakapacker
10-
webpack: sh -c 'bundle exec rake react_on_rails:locale && rm -rf public/packs/* || true && bin/shakapacker -w'
1+
web: bin/rails server -p 3000
2+
js: bin/shakapacker --watch
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
class HelloWorldController < ApplicationController
4+
layout "hello_world"
5+
6+
def index
7+
@hello_world_props = { name: "Stranger" }
8+
end
9+
end
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import ReactOnRails from 'react-on-rails';
2+
// eslint-disable-next-line import/no-webpack-loader-syntax
3+
import 'expose-loader?exposes=$,jQuery!jquery';
4+
import 'jquery-ujs';
5+
6+
import App from '../bundles/comments/startup/App';
7+
import RouterApp from '../bundles/comments/startup/ClientRouterApp';
8+
import SimpleCommentScreen from '../bundles/comments/components/SimpleCommentScreen/SimpleCommentScreen';
9+
import routerCommentsStore from '../bundles/comments/store/routerCommentsStore';
10+
import commentsStore from '../bundles/comments/store/commentsStore';
11+
import NavigationBarApp from '../bundles/comments/startup/NavigationBarApp';
12+
import Footer from '../bundles/comments/components/Footer/Footer';
13+
import RescriptShow from '../bundles/comments/rescript/ReScriptShow.bs.js';
14+
15+
import '../assets/styles/application';
16+
17+
ReactOnRails.setOptions({
18+
// traceTurbolinks: process.env.TRACE_TURBOLINKS, // eslint-disable-line no-undef
19+
// process.env.TRACE_TURBOLINKS -> error: development is not defined
20+
traceTurbolinks: true,
21+
});
22+
23+
ReactOnRails.register({
24+
App,
25+
RouterApp,
26+
NavigationBarApp,
27+
SimpleCommentScreen,
28+
Footer,
29+
RescriptShow,
30+
});
31+
32+
ReactOnRails.registerStore({
33+
routerCommentsStore,
34+
commentsStore,
35+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Placeholder comment - auto-generated imports will be prepended here by react_on_rails:generate_packs
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import ReactOnRails from 'react-on-rails';
2+
import 'jquery-ujs';
3+
import { Turbo } from '@hotwired/turbo-rails';
4+
5+
// eslint-disable-next-line no-unused-vars
6+
import controllers from '../controllers';
7+
8+
import NavigationBarApp from '../bundles/comments/startup/NavigationBarApp';
9+
import Footer from '../bundles/comments/components/Footer/Footer';
10+
11+
import '../assets/styles/application';
12+
13+
Turbo.session.drive = false;
14+
15+
ReactOnRails.setOptions({
16+
// traceTurbolinks: process.env.TRACE_TURBOLINKS, // eslint-disable-line no-undef
17+
// process.env.TRACE_TURBOLINKS -> error: development is not defined
18+
traceTurbolinks: true,
19+
});
20+
21+
ReactOnRails.register({
22+
NavigationBarApp,
23+
Footer,
24+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React, { useState } from 'react';
2+
import * as style from './HelloWorld.module.css';
3+
4+
const HelloWorld = (props) => {
5+
const [name, setName] = useState(props.name);
6+
7+
return (
8+
<div>
9+
<h3>Hello, {name}!</h3>
10+
<hr />
11+
<form>
12+
<label className={style.bright} htmlFor="name">
13+
Say hello to:
14+
<input id="name" type="text" value={name} onChange={(e) => setName(e.target.value)} />
15+
</label>
16+
</form>
17+
</div>
18+
);
19+
};
20+
21+
export default HelloWorld;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.bright {
2+
color: green;
3+
font-weight: bold;
4+
}

0 commit comments

Comments
 (0)