You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/oss/getting-started/installation-into-an-existing-rails-app.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,9 @@ Use this path when you already have a Rails application and want React on Rails
6
6
7
7
- Rails 7+ is recommended. Rails 5.2+ can work, but Webpacker-era apps usually need an incremental upgrade first.
8
8
- If your app still uses `webpacker`, expect this to be a two-step migration: move to `shakapacker`, then install React on Rails.
9
+
- If `bundle install` is already failing on older native gems such as `pg`, `nio4r`, `mysql2`, or `msgpack`, fix that baseline first. React on Rails installation cannot get past a broken app bundle.
10
+
- If your repo has a `yarn.lock` but no `"packageManager"` field in `package.json`, add one before introducing Shakapacker 9. Example: `"packageManager": "yarn@1.22.22"`.
11
+
- The install generator boots your app. Make sure `config/database.yml` exists and any required env vars for initializers are set before running `rails generate`.
9
12
- If your app is Rails 5 API-only, first [convert it to a standard Rails app](../migrating/convert-rails-5-api-only-app.md).
10
13
- Commit or stash your current work if you want the generated diff to be easier to review. The generator updates files like `bin/dev`, `config/shakapacker.yml`, routes, initializers, and sample views/controllers.
Copy file name to clipboardExpand all lines: docs/oss/migrating/migrating-from-react-rails.md
+15-6Lines changed: 15 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,13 +2,18 @@
2
2
3
3
This migration is easiest when the app is already on a modern Rails + Shakapacker baseline.
4
4
5
+
If your `react-rails` app uses Vite or another non-Shakapacker asset setup, use this page for the helper and registration changes, but follow [Migrate from `vite_rails`](./migrating-from-vite-rails.md) for the asset-pipeline and entrypoint steps.
6
+
5
7
## Preflight
6
8
7
9
Before swapping gems, check these first:
8
10
9
11
1.**Webpacker vs Shakapacker**: if the app still uses `webpacker`, migrate to `shakapacker` first.
10
12
2.**Bundler age**: some older `react-rails` apps still carry Bundler 1.x lockfiles. Those can fail on modern Ruby before you even reach the migration work.
11
-
3.**Rails age**: current `react_on_rails` requires Rails 5.2+. Rails 5.1 / Webpacker 3 apps are usually a staged migration, not a one-command migration.
13
+
3.**Native gem age**: older lockfiles often pin `nio4r`, `pg`, or `mysql2` versions that fail to compile on current macOS and Ruby before the migration even starts.
14
+
4.**App boot readiness**: the React on Rails install generator boots the full Rails app. Make sure `config/database.yml` exists and required env vars for initializers are set.
15
+
5.**Package manager metadata**: if the repo has a `yarn.lock` but no `"packageManager"` field in `package.json`, add one before introducing Shakapacker 9. Example: `"packageManager": "yarn@1.22.22"`.
16
+
6.**Rails age**: current `react_on_rails` requires Rails 5.2+. Rails 5.1 / Webpacker 3 apps are usually a staged migration, not a one-command migration.
12
17
13
18
If you are already on `shakapacker` 7+ and React 18+, the migration is mostly about helper syntax, component registration, and generated defaults.
14
19
@@ -19,11 +24,14 @@ bundle _2.3.26_ lock --update
19
24
bundle _2.3.26_ install
20
25
```
21
26
27
+
If the first failure is a native gem compile error, solve that before swapping to React on Rails. Typical examples are `nio4r` in older Rails/Webpacker apps and `pg` or `mysql2` in apps with older database adapters pinned in the lockfile.
28
+
22
29
1. Update Deps
23
30
1. Replace `react-rails` in `Gemfile` with `react_on_rails` and make sure `shakapacker` is present.
24
31
2. Remove `react_ujs` from `package.json`.
25
-
3. Run `bundle install` and your package manager's install command.
26
-
4. Commit changes.
32
+
3. If the repo uses Yarn and `package.json` does not already declare it, add `"packageManager": "yarn@1.22.22"` before booting the app with Shakapacker 9.
33
+
4. Run `bundle install` and your package manager's install command.
34
+
5. Commit changes.
27
35
28
36
2. Run `rails g react_on_rails:install` but do not commit the change. `react_on_rails` installs node dependencies and also creates sample React component, Rails view/controller, and updates `config/routes.rb`.
29
37
@@ -60,6 +68,7 @@ then treat the migration as:
60
68
1. Move from `webpacker` to `shakapacker`.
61
69
2. If the app is still on Rails 5.1, upgrade Rails to 5.2+ before adding current `react_on_rails`.
62
70
3. Remove `react_ujs`.
63
-
4. Run the React on Rails install generator.
64
-
5. Replace helper syntax and component registration.
65
-
6. Review `bin/dev`, `config/shakapacker.yml`, and webpack config diffs before committing.
71
+
4. Ensure the app can boot for generator execution (`config/database.yml`, initializer env vars, package manager metadata).
72
+
5. Run the React on Rails install generator.
73
+
6. Replace helper syntax and component registration.
74
+
7. Review `bin/dev`, `config/shakapacker.yml`, and webpack config diffs before committing.
Copy file name to clipboardExpand all lines: docs/oss/migrating/migrating-from-vite-rails.md
+11-1Lines changed: 11 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,8 +17,10 @@ If your app is already happy with a Vite-only client-rendered setup, this migrat
17
17
18
18
Before you start, make sure the current app still installs cleanly on the Ruby and Node versions you plan to use for the migration.
19
19
20
-
- If `bundle install` fails on older native gems such as `pg`, `nio4r`, or `msgpack`, refresh those gems or use the Ruby version already pinned by the app before introducing React on Rails.
20
+
- If `bundle install` fails on older native gems such as `pg`, `nio4r`, `mysql2`, or `msgpack`, refresh those gems or use the Ruby version already pinned by the app before introducing React on Rails.
21
21
- If the app has an older Bundler-era lockfile, refresh that lockfile first.
22
+
- If the repo uses Yarn and has a `yarn.lock` but no `"packageManager"` field in `package.json`, add one before introducing Shakapacker 9. Example: `"packageManager": "yarn@1.22.22"`.
23
+
- The React on Rails install generator boots the full app. Make sure `config/database.yml` exists and any required env vars for initializers are set before you run it.
22
24
- Commit or stash your current work so the generator diff is easier to review.
23
25
24
26
Then inventory the Vite-specific pieces in your app:
If you use Yarn and `package.json` does not already declare it, set the package manager before running the generator:
52
+
53
+
```bash
54
+
npm pkg set packageManager="yarn@1.22.22"
55
+
```
56
+
49
57
The generator adds the React on Rails initializer, `bin/dev`, Shakapacker config, example routes, and the server bundle entrypoint.
50
58
51
59
## 2. Replace Vite layout tags
@@ -180,3 +188,5 @@ one reasonable React on Rails target is:
180
188
- Turbo usage, if your app already uses it
181
189
182
190
The migration is mostly about asset/build integration, mounting strategy, and optional SSR capability.
191
+
192
+
One practical detail from real app migrations: if the generator fails while booting your app, treat that as an application preflight problem first, not a React on Rails problem. Missing `APP_URL`-style env vars or an absent `config/database.yml` can stop the migration before any React on Rails files are generated.
Copy file name to clipboardExpand all lines: docs/oss/upgrading/upgrading-react-on-rails.md
+6-1Lines changed: 6 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,10 @@ Before changing versions, check these first:
29
29
2.**Bundler age**: legacy apps may have lockfiles created by Bundler 1.x. Those lockfiles can fail on modern Ruby before the React on Rails upgrade even starts.
30
30
3.**Rails version**: current `react_on_rails` requires Rails 5.2+. Rails 5.1 apps need a Rails upgrade before they can bundle v16.
31
31
4.**Asset stack**: if the app still uses `webpacker`, upgrade to `shakapacker` first.
32
-
5.**Version pinning**: use exact gem and npm package versions for React on Rails-related packages. Avoid `^`, `~`, or `*`.
32
+
5.**Native gem age**: older `pg`, `nio4r`, `mysql2`, or `msgpack` versions can fail on current Ruby or macOS before the React on Rails upgrade even begins.
33
+
6.**App boot readiness**: the install generator boots the full Rails app. Make sure `config/database.yml` exists and required env vars for initializers are set.
34
+
7.**Package manager metadata**: if the repo has a `yarn.lock` but no `"packageManager"` field in `package.json`, add one before introducing Shakapacker 9. Example: `"packageManager": "yarn@1.22.22"`.
35
+
8.**Version pinning**: use exact gem and npm package versions for React on Rails-related packages. Avoid `^`, `~`, or `*`.
33
36
34
37
If your app is both Ruby/Bundler-old and Webpacker-old, do those upgrades first. Trying to jump directly from a Rails 5 / Webpacker 3 / Bundler 1 stack to current React on Rails is usually more than one migration.
35
38
@@ -41,6 +44,8 @@ bundle lock --update
41
44
bundle install
42
45
```
43
46
47
+
If `bundle install` is failing even earlier on native gems, fix that baseline before upgrading React on Rails. Common examples from real upgrades are `pg` compile errors in older Postgres apps, `nio4r` failures in older Rails/Webpacker stacks, or `mysql2` linker issues on Homebrew/macOS setups.
48
+
44
49
## Upgrading Precompile Hooks for SSR + HMR
45
50
46
51
If your app uses server-side rendering with HMR, Shakapacker commonly runs two webpack processes during development (client HMR and server watcher). In that setup, direct-command precompile hooks are more fragile because each process can trigger the hook.
0 commit comments