Add Spring.allow_reloading_disabled opt-in#755
Merged
Conversation
9893aa3 to
926ee4f
Compare
By default Spring refuses to boot when `config.cache_classes = true`
(a.k.a. `config.enable_reloading = false`) via the
`:ensure_reloading_is_enabled` initializer, with the message "Spring
reloads, and therefore needs the application to have reloading
enabled."
That guard predates the recognition that Spring's reload mechanism is
mold-restart-on-file-change via its own watcher (loaded application
features + initializers + config paths) — which works regardless of
whether Rails' in-process reloader is enabled. For projects that want
to disable Rails' reloader (e.g. to shed the per-serve
`reloaders.any?(&:updated?)` stat() pass over thousands of watched
files in large monorepos), the guard is unnecessarily strict.
This commit adds `Spring.allow_reloading_disabled` as an explicit
opt-in. Default remains `false` (the existing strict check). When set
to `true` the initializer is not registered and Spring boots normally
with reloading disabled.
The docstring on `Spring.allow_reloading_disabled` spells out what the
user gives up:
1. Rails' `app.reloader.reload!` becomes a no-op. Anything that
depends on it won't fire between Spring serves.
2. With Zeitwerk + reloading disabled, autoloaded constants are
non-reloadable. Tests that rely on the reloader resetting class
state between runs may break.
3. The user is responsible for asserting that lazy resources (routes,
I18n, view paths) stay unmaterialized in the Spring mold so that
each fork loads them fresh.
Acceptance test added covering the new opt-in.
Co-authored-by: AI (Pi/Claude Opus 4.7) <noreply@pi.dev>
926ee4f to
84d5c98
Compare
a02e823 to
84d5c98
Compare
rafaelfranca
approved these changes
May 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
Spring.allow_reloading_disabledas an opt-in. The default:ensure_reloading_is_enabledinitializer is unchanged and is the right default. Rails apps almost universally depend onRails.application.reloader.reload!between Spring serves to pick up edits (route redraw, I18n reload,to_preparecallbacks, etc..). Booting Spring with that disabled is wrong for those apps and the check correctly refuses.why?
The opt-in is useful, when running test, for apps where every resource that would require a reloader (translations, routes, ...) are lazy-loaded inside the forked child, and thus not loaded in the Spring parent.
In such apps, running with
config.enable_reloadingsaves quite a bit of time on every test run, particularly on very large apps, where the reloaders have tostattens of thousands of files on every test run to figure out if reloading is required.