Skip to content

Commit ec65794

Browse files
committed
Tighten migration preflights from validation runs
1 parent 33c2fa5 commit ec65794

4 files changed

Lines changed: 35 additions & 8 deletions

File tree

docs/oss/getting-started/installation-into-an-existing-rails-app.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Use this path when you already have a Rails application and want React on Rails
66

77
- Rails 7+ is recommended. Rails 5.2+ can work, but Webpacker-era apps usually need an incremental upgrade first.
88
- 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`.
912
- If your app is Rails 5 API-only, first [convert it to a standard Rails app](../migrating/convert-rails-5-api-only-app.md).
1013
- 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.
1114

docs/oss/migrating/migrating-from-react-rails.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22

33
This migration is easiest when the app is already on a modern Rails + Shakapacker baseline.
44

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+
57
## Preflight
68

79
Before swapping gems, check these first:
810

911
1. **Webpacker vs Shakapacker**: if the app still uses `webpacker`, migrate to `shakapacker` first.
1012
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.
1217

1318
If you are already on `shakapacker` 7+ and React 18+, the migration is mostly about helper syntax, component registration, and generated defaults.
1419

@@ -19,11 +24,14 @@ bundle _2.3.26_ lock --update
1924
bundle _2.3.26_ install
2025
```
2126

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+
2229
1. Update Deps
2330
1. Replace `react-rails` in `Gemfile` with `react_on_rails` and make sure `shakapacker` is present.
2431
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.
2735

2836
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`.
2937

@@ -60,6 +68,7 @@ then treat the migration as:
6068
1. Move from `webpacker` to `shakapacker`.
6169
2. If the app is still on Rails 5.1, upgrade Rails to 5.2+ before adding current `react_on_rails`.
6270
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.

docs/oss/migrating/migrating-from-vite-rails.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ If your app is already happy with a Vite-only client-rendered setup, this migrat
1717

1818
Before you start, make sure the current app still installs cleanly on the Ruby and Node versions you plan to use for the migration.
1919

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.
2121
- 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.
2224
- Commit or stash your current work so the generator diff is easier to review.
2325

2426
Then inventory the Vite-specific pieces in your app:
@@ -46,6 +48,12 @@ bundle add react_on_rails --strict
4648
bundle exec rails generate react_on_rails:install
4749
```
4850

51+
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+
4957
The generator adds the React on Rails initializer, `bin/dev`, Shakapacker config, example routes, and the server bundle entrypoint.
5058

5159
## 2. Replace Vite layout tags
@@ -180,3 +188,5 @@ one reasonable React on Rails target is:
180188
- Turbo usage, if your app already uses it
181189

182190
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.

docs/oss/upgrading/upgrading-react-on-rails.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ Before changing versions, check these first:
2929
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.
3030
3. **Rails version**: current `react_on_rails` requires Rails 5.2+. Rails 5.1 apps need a Rails upgrade before they can bundle v16.
3131
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 `*`.
3336

3437
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.
3538

@@ -41,6 +44,8 @@ bundle lock --update
4144
bundle install
4245
```
4346

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+
4449
## Upgrading Precompile Hooks for SSR + HMR
4550

4651
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

Comments
 (0)