Skip to content

Commit 43ff2bf

Browse files
committed
Autoloading notes in the upgrading guide
1 parent e0d77f1 commit 43ff2bf

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

guides/source/upgrading_ruby_on_rails.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,58 @@ To allow you to upgrade to new defaults one by one, the update task has created
7878
Upgrading from Rails 6.1 to Rails 7.0
7979
-------------------------------------
8080

81+
### Applications need to run in `zeitwerk` mode
82+
83+
Applications still running in `classic` mode have to switch to `zeitwerk` mode. Please check the [upgrading guide for Rails 6.0](https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#autoloading) for details.
84+
85+
### The setter `config.autoloader=` has been deleted
86+
87+
In Rails 7 there is no configuration point to set the autoloading mode, `config.autoloader=` has been deleted. If you had it set to `:zeitwerk` for whatever reason, just remove it.
88+
89+
### `ActiveSupport::Dependencies` private API has been deleted
90+
91+
The private API of `ActiveSupport::Dependencies` has been deleted. That includes methods like `hook!`, `unhook!`, `depend_on`, `require_or_load`, `mechanism`, and many others.
92+
93+
A few of highlights:
94+
95+
* If you used `ActiveSupport::Dependencies.constantize` or ``ActiveSupport::Dependencies.safe_constantize`, just change them to `String#constantize` or `String#safe_constantize`.
96+
97+
```ruby
98+
ActiveSupport::Dependencies.constantize("User") # NO LONGER POSSIBLE
99+
"User".constantize # 👍
100+
```
101+
102+
* Any usage of `ActiveSupport::Dependencies.mechanism`, reader or writer, has to be replaced by accessing `config.cache_classes` accordingly.
103+
104+
* If you want to trace the activity of the autoloader, `ActiveSupport::Dependencies.verbose=` is no longer available, just throw `Rails.autoloaders.log!` in `config/application.rb`.
105+
106+
Auxiliary internal classes or modules are also gone, like like `ActiveSupport::Dependencies::Reference`, `ActiveSupport::Dependencies::Blamable`, and others.
107+
108+
### Autoloading during initialization
109+
110+
Applications that autoloaded reloadable constants during initialization outside of `to_prepare` blocks got those constants unloaded and had this warning issued since Rails 6.0:
111+
112+
```
113+
DEPRECATION WARNING: Initialization autoloaded the constant ....
114+
115+
Being able to do this is deprecated. Autoloading during initialization is going
116+
to be an error condition in future versions of Rails.
117+
118+
...
119+
```
120+
121+
If you still get this warning in the logs, please check the section about autoloading when the application boots in the [autoloading guide](https://guides.rubyonrails.org/v7.0/autoloading_and_reloading_constants.html#autoloading-when-the-application-boots). You'd get a `NameError` in Rails 7 otherwise.
122+
123+
### Ability to configure `config.autoload_once_paths`
124+
125+
`config.autoload_once_paths` can be set in the body of the application class defined in `config/application.rb` or in the configuration for environments in `config/environments/*`.
126+
127+
Similarly, engines can configure that collection in the class body of the engine class or in the configuration for environments.
128+
129+
After that, the collection is frozen, and you can autoload from those paths. In particular, you can autoload from there during initialization. They are managed by the `Rails.autoloaders.once` autoloader, which does not reload, only autoloads/eager loads.
130+
131+
If you configured this setting after the environments configuration has been processed and are getting `FrozenError`, please just move the code.
132+
81133
### `ActionDispatch::Request#content_type` now returned Content-Type header as it is.
82134

83135
Previously, `ActionDispatch::Request#content_type` returned value does NOT contain charset part.
@@ -173,7 +225,7 @@ FFmpeg v3.4+.
173225

174226
Image transformation will now use libvips instead of ImageMagick. This will reduce
175227
the time taken to generate variants as well as CPU and memory usage, improving response
176-
times in apps that rely on active storage to serve their images.
228+
times in apps that rely on active storage to serve their images.
177229

178230
The `:mini_magick` option is not being deprecated, so it is fine to keep using it.
179231

0 commit comments

Comments
 (0)