Skip to content

Commit f6918a5

Browse files
authored
Merge pull request rails#51909 from rails/rm-release-notes
Draft of the release notes
2 parents 58883a5 + b0efe42 commit f6918a5

File tree

2 files changed

+275
-10
lines changed

2 files changed

+275
-10
lines changed

guides/source/7_2_release_notes.md

Lines changed: 275 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,26 @@ Ruby on Rails 7.2 Release Notes
55

66
Highlights in Rails 7.2:
77

8+
* Development containers configuration for applications.
9+
* Add browser version guard by default.
10+
* Make Ruby 3.1 the new minimum version.
11+
* Default Progressive Web Application (PWA) files.
12+
* Add omakase RuboCop rules by default.
13+
* Add GitHub CI workflow by default to new applications.
14+
* Add Brakeman by default to new applications.
15+
* Set a new default for the Puma thread count.
16+
* Prevent jobs from being scheduled within transactions.
17+
* Per transaction commit and rollback callbacks.
18+
* Enable YJIT by default if running Ruby 3.3+.
19+
* New design for the Rails guides.
20+
* Setup jemalloc in default Dockerfile to optimize memory allocation.
21+
* Suggest puma-dev configuration in bin/setup.
22+
23+
These release notes cover only the major changes. To learn about various bug
24+
fixes and changes, please refer to the changelogs or check out the [list of
25+
commits](https://github.com/rails/rails/commits/7-2-stable) in the main Rails
26+
repository on GitHub.
27+
828
--------------------------------------------------------------------------------
929

1030
Upgrading to Rails 7.2
@@ -21,6 +41,252 @@ guide.
2141
Major Features
2242
--------------
2343

44+
### Development containers configuration for applications
45+
46+
A [development container](https://containers.dev/) (or dev container for short) allows you to use a container
47+
as a full-featured development environment.
48+
49+
Rails 7.2 adds the ability to generate a development container configuration for your application. This configuration
50+
includes a `.devcontainer` folder with a `Dockerfile`, a `docker-compose.yml` file, and a `devcontainer.json` file.
51+
52+
By default, the dev container contains the following:
53+
54+
* A Redis container for use with Kredis, Action Cable, etc.
55+
* A database (SQLite, Postgres, MySQL or MariaDB)
56+
* A Headless Chrome container for system tests
57+
* Active Storage configured to use the local disk and with preview features working
58+
59+
To generate a new application with a development container, you can run:
60+
61+
```bash
62+
rails new myapp --devcontainer
63+
```
64+
65+
For existing applications, a `devcontainer` command is now available:
66+
67+
```bash
68+
rails devcontainer
69+
```
70+
71+
For more information, see the [Getting Started with Dev Containers](https://edgeguides.rubyonrails.org/getting_started_with_devcontainer.html) guide.
72+
73+
### Add browser version guard by default
74+
75+
Rails now adds the ability to specify the browser versions that will be allowed to access all actions
76+
(or some, as limited by `only:` or `except:`).
77+
78+
Only browsers matched in the hash or named set passed to `versions:` will be blocked if they're below the versions
79+
specified.
80+
81+
This means that all other unknown browsers, as well as agents that aren't reporting a user-agent header, will be allowed access.
82+
83+
A browser that's blocked will by default be served the file in `public/406-unsupported-browser.html` with a HTTP status
84+
code of "406 Not Acceptable".
85+
86+
Examples:
87+
88+
```ruby
89+
class ApplicationController < ActionController::Base
90+
# Allow only browsers natively supporting webp images, web push, badges, import maps, CSS nesting + :has
91+
allow_browser versions: :modern
92+
end
93+
94+
class ApplicationController < ActionController::Base
95+
# All versions of Chrome and Opera will be allowed, but no versions of "internet explorer" (ie). Safari needs to be 16.4+ and Firefox 121+.
96+
allow_browser versions: { safari: 16.4, firefox: 121, ie: false }
97+
end
98+
99+
class MessagesController < ApplicationController
100+
# In addition to the browsers blocked by ApplicationController, also block Opera below 104 and Chrome below 119 for the show action.
101+
allow_browser versions: { opera: 104, chrome: 119 }, only: :show
102+
end
103+
```
104+
105+
Newly generated applications have this guard set in `ApplicationController`.
106+
107+
For more information, see the [allow_browser](https://api.rubyonrails.org/classes/ActionController/AllowBrowser/ClassMethods.html#method-i-allow_browser)
108+
documentation.
109+
110+
### Make Ruby 3.1 the new minimum version
111+
112+
Until now, Rails only dropped compatibility with older Rubies on new majors version.
113+
We are changing this policy because it causes us to keep compatibility with long
114+
unsupported versions of Ruby or to bump the Rails major version more often, and to
115+
drop multiple Ruby versions at once when we bump the major.
116+
117+
We will now drop Ruby versions that are end-of-life on minor Rails versions at the time of the release.
118+
119+
For Rails 7.2, Ruby 3.1 is the new minimum version.
120+
121+
### Default Progressive Web Application (PWA) files
122+
123+
In preparation to better supporting the creation of PWA applications with Rails, we now generate default PWA files for the manifest
124+
and service worker, which are served from `app/views/pwa` and can be dynamically rendered through ERB. Those files
125+
are mounted explicitly at the root with default routes in the generated routes file.
126+
127+
For more information, see the [pull request adding the feature](https://github.com/rails/rails/pull/50528).
128+
129+
### Add omakase RuboCop rules by default
130+
131+
Rails applications now come with [RuboCop](https://rubocop.org/) configured with a set of rules from [rubocop-rails-omakase](https://github.com/rails/rubocop-rails-omakase) by default.
132+
133+
Ruby is a beautifully expressive language that not only tolerates many different dialects, but celebrates their
134+
diversity. It was never meant as a language to be written exclusively in a single style across all libraries,
135+
frameworks, or applications. If you or your team has developed a particular house style that brings you joy,
136+
you should cherish that.
137+
138+
This collection of RuboCop styles is for those who haven't committed to any specific dialect already. Who would just
139+
like to have a reasonable starting point, and who will benefit from some default rules to at least start a consistent
140+
approach to Ruby styling.
141+
142+
These specific rules aren't right or wrong, but merely represent the idiosyncratic aesthetic sensibilities of Rails'
143+
creator. Use them whole, use them as a starting point, use them as inspiration, or however you see fit.
144+
145+
### Add GitHub CI workflow by default to new applications
146+
147+
Rails now adds a default GitHub CI workflow file to new applications. This will get especially newcomers off to a good
148+
start with automated scanning, linting, and testing. We find that a natural continuation for the modern age of what
149+
we've done since the start with unit tests.
150+
151+
It's of course true that GitHub Actions are a commercial cloud product for private repositories after you've used the
152+
free tokens. But given the relationship between GitHub and Rails, the overwhelming default nature of the platform for
153+
newcomers, and the value of teaching newcomers good CI habits, we find this to be an acceptable trade-off.
154+
155+
### Add Brakeman by default to new applications
156+
157+
[Brakeman](https://brakemanscanner.org/) is a great way to prevent common security vulnerabilities in Rails from going
158+
into production.
159+
160+
New applications come with Brakeman installed and combined with the GitHub CI workflow, it will run automatically on
161+
every push.
162+
163+
### Set a new default for the Puma thread count
164+
165+
Rails changed the default number of threads in Puma from 5 to 3.
166+
167+
Due to the nature of well-optimized Rails applications, with quick SQL queries and slow 3rd-party calls running via jobs,
168+
Ruby can spend a significant amount of time waiting for the Global VM Lock (GVL) to release when the thread count is too
169+
high, which is hurting latency (request response time).
170+
171+
After careful consideration, investigation, and based on battle-tested experience from applications running in
172+
production, we decided that a default of 3 threads is a good balance between concurrency and performance.
173+
174+
You can follow a very detailed discussion about this change in [the issue](https://github.com/rails/rails/issues/50450).
175+
176+
### Prevent jobs from being scheduled within transactions
177+
178+
A common mistake with Active Job is to enqueue jobs from inside a transaction, causing them to potentially be picked
179+
and ran by another process, before the transaction is committed, which result in various errors.
180+
181+
```ruby
182+
Topic.transaction do
183+
topic = Topic.create
184+
185+
NewTopicNotificationJob.perform_later(topic)
186+
end
187+
```
188+
189+
Now Active Job will automatically defer the enqueuing to after the transaction is committed, and drop the job if the
190+
transaction is rolled back.
191+
192+
Various queue implementations can chose to disable this behavior, and users can disable it, or force it on a per job
193+
basis:
194+
195+
```ruby
196+
class NewTopicNotificationJob < ApplicationJob
197+
self.enqueue_after_transaction_commit = false
198+
end
199+
```
200+
201+
### Per transaction commit and rollback callbacks
202+
203+
This is now possible due to a new feature that allows registering transaction callbacks outside of a record.
204+
205+
`ActiveRecord::Base.transaction` now yields an `ActiveRecord::Transaction` object, which allows registering callbacks
206+
on it.
207+
208+
```ruby
209+
Article.transaction do |transaction|
210+
article.update(published: true)
211+
212+
transaction.after_commit do
213+
PublishNotificationMailer.with(article: article).deliver_later
214+
end
215+
end
216+
```
217+
218+
`ActiveRecord::Base.current_transaction` was also added to allow to register callbacks on it.
219+
220+
```ruby
221+
Article.current_transaction.after_commit do
222+
PublishNotificationMailer.with(article: article).deliver_later
223+
end
224+
```
225+
226+
And finally, `ActiveRecord.after_all_transactions_commit` was added, for code that may run either inside or outside a
227+
transaction and needs to perform work after the state changes have been properly persisted.
228+
229+
```ruby
230+
def publish_article(article)
231+
article.update(published: true)
232+
233+
ActiveRecord.after_all_transactions_commit do
234+
PublishNotificationMailer.with(article: article).deliver_later
235+
end
236+
end
237+
```
238+
239+
See [#51474](https://github.com/rails/rails/pull/51474) and [#51426](https://github.com/rails/rails/pull/51426) for more information:
240+
241+
### Enable YJIT by default if running Ruby 3.3+
242+
243+
YJIT is Ruby's JIT compiler that is available in CRuby since Ruby 3.1. It can provide significant performance
244+
improvements for Rails applications, offering 15-25% latency improvements.
245+
246+
In Rails 7.2, YJIT is enabled by default if running Ruby 3.3 or newer.
247+
248+
You can disable YJIT by setting:
249+
250+
```ruby
251+
Rails.application.config.yjit = false
252+
```
253+
254+
### New design for the Rails guides
255+
256+
When Rails 7.0 landed in December 2021, it came with a fresh new homepage and a new boot screen. The design of the
257+
guides, however, has remained largely untouched since 2009 - a point which hasn’t gone unnoticed (we heard your feedback).
258+
259+
With all of the work right now going into removing complexity from the Rails framework and making the documentation
260+
consistent, clear, and up-to-date, it was time to tackle the design of the guides and make them equally modern, simple,
261+
and fresh.
262+
263+
We worked with UX designer [John Athayde](https://meticulous.com/) to take the look and feel of the homepage and
264+
transfer that over to the Rails guides to make them clean, sleek, and up-to-date.
265+
266+
The layout will remain the same, but from today you will see the following changes reflected in the guides:
267+
268+
* Cleaner, less busy design.
269+
* Fonts, color scheme, and logo more consistent with the home page.
270+
* Updated iconography.
271+
* Simplified navigation.
272+
* Sticky "Chapters" navbar when scrolling.
273+
274+
See the [announcement blog post for some before/after images](https://rubyonrails.org/2024/3/20/rails-guides-get-a-facelift).
275+
276+
### Setup jemalloc in default Dockerfile to optimize memory allocation
277+
278+
[Ruby's use of `malloc` can create memory fragmentation problems, especially when using multiple threads](https://www.speedshop.co/2017/12/04/malloc-doubles-ruby-memory.html)
279+
like Puma does. Switching to an allocator that uses different patterns to avoid fragmentation can decrease memory usage
280+
by a substantial margin.
281+
282+
Rails 7.2 now includes [jemalloc](https://jemalloc.net/) in the default Dockerfile to optimize memory allocation.
283+
284+
### Suggest puma-dev configuration in bin/setup
285+
286+
[Puma-dev](https://github.com/puma/puma-dev) is the golden path for developing multiple Rails applications locally, if you're not using Docker.
287+
288+
Rails now suggests how to get that setup in a new comment you'll find in `bin/setup`.
289+
24290
Railties
25291
--------
26292

@@ -36,21 +302,21 @@ Please refer to the [Changelog][railties] for detailed changes.
36302

37303
* Remove deprecated `find_cmd_and_exec` console helper.
38304

39-
* Remove support for `oracle`, `sqlserver`, and JRuby specific database adapters from the rails new
40-
and rails db:system:change commands.
305+
* Remove support for `oracle`, `sqlserver`, and JRuby specific database adapters from the `new`
306+
and `db:system:change` `rails` commands.
41307

42308
* Remove `config.public_file_server.enabled` option from the generators.
43309

44310
### Deprecations
45311

46312
### Notable changes
47313

48-
* Add `RuboCop` with rules from [rubocop-rails-omakase](https://github.com/rails/rubocop-rails-omakase)
314+
* Add RuboCop with rules from [rubocop-rails-omakase](https://github.com/rails/rubocop-rails-omakase)
49315
by default in both new applications and plugins.
50316

51-
* Add `Brakeman` with default configuration for security checks in new applications.
317+
* Add Brakeman with default configuration for security checks in new applications.
52318

53-
* Add GitHub CI files for `Dependabot`, `Brakeman`, `RuboCop`, and running tests by default for new applications and plugins.
319+
* Add GitHub CI files for Dependabot, Brakeman, RuboCop, and running tests by default for new applications and plugins.
54320

55321
* YJIT is now enabled by default for new applications running on Ruby 3.3+.
56322

@@ -62,10 +328,10 @@ Please refer to the [Changelog][railties] for detailed changes.
62328

63329
* Introduce `Rails::Generators::Testing::Assertions#assert_initializer` to test initializers.
64330

65-
* System tests now use headless Chrome by default for new applications.
331+
* System tests now use Headless Chrome by default for new applications.
66332

67-
* Support the `BACKTRACE` environment variable to turn off backtrace cleaning in normal server runnings.
68-
Previously, this was only available for the testing.
333+
* Support the `BACKTRACE` environment variable to turn off backtrace cleaning in normal server runnings.
334+
Previously, this was only available for testing.
69335

70336
* Add default Progressive Web App (PWA) files for the manifest and service worker, served from `app/views/pwa`,
71337
and make them dynamically renderable through ERB.
@@ -113,7 +379,7 @@ Please refer to the [Changelog][action-view] for detailed changes.
113379

114380
### Removals
115381

116-
* Remove deprecated `@rails/ujs` in favor of `Turbo`.
382+
* Remove deprecated `@rails/ujs` in favor of Turbo.
117383

118384
### Deprecations
119385

guides/source/documents.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@
335335
name: Version 7.2 - ?
336336
url: 7_2_release_notes.html
337337
description: Release notes for Rails 7.2.
338-
work_in_progress: true
339338
-
340339
name: Version 7.1 - October 2023
341340
url: 7_1_release_notes.html

0 commit comments

Comments
 (0)