Skip to content

Fix compensation of ERB line numbers on the next major Rails version - #2780

Merged
joelhawksley merged 3 commits into
ViewComponent:mainfrom
czj:rails-9-erb-newline
Nov 9, 2026
Merged

joelhawksley merged 3 commits into
ViewComponent:mainfrom
czj:rails-9-erb-newline

Conversation

@czj

@czj czj commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

What are you trying to accomplish?

Rails 8.1 added a newline to compiled ERB output (rails/rails#53731), and Template#erb_newline_compensation_needed? corrects line numbers for it. The check is:

Rails::VERSION::MAJOR >= 8 && Rails::VERSION::MINOR > 0

Nothing is broken today: it's correct for 8.0 and every 8.x after it. But it will be false on the .0 release of the next major version, since MINOR is 0 there. Line numbers would stop being corrected, and backtraces from annotated HTML+ERB templates would point one line off. The gemspec allows >= 7.1.0 with no upper bound, so apps can install that release on day one. This is a small change now to avoid a hard-to-trace bug later.

What approach did you choose and why?

The check now compares Rails.gem_version with 8.1.0.alpha, so Rails main prereleases of 8.1 still count. The test skips that used the same condition now use the same comparison. rendering_test.rb compared Rails::VERSION::STRING < "8.0" as strings, which would break at 10.0, so I fixed that too.

Anything you want to highlight for special attention from reviewers?

The regression test swaps Rails::VERSION::MAJOR/MINOR/STRING inside a block, restores them afterwards, and checks that a hypothetical 9.0.0 compensates and 8.0.3 doesn't. On main, it fails for 9.0.0. I couldn't run the suite locally.

czj and others added 3 commits November 7, 2026 07:11
Rails 8.1 added a newline to compiled ERB output, which ViewComponent
compensates for when it compiles a template. The check required
`MAJOR >= 8 && MINOR > 0`, which is false on the `.0` release of any
later major version, so backtraces from annotated HTML+ERB templates
would point one line off there. Nothing is broken on 8.x today.

Compare `Rails.gem_version` instead, here and in the tests that skipped
on the same condition or compared version strings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VLwjZw7FEdBpwALzxXxXnJ
It lived in a class that skips before Rails 8.1, although the version
check it covers doesn't depend on the installed Rails. Also compare the
major version directly in the backtrace index tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VLwjZw7FEdBpwALzxXxXnJ
@joelhawksley
joelhawksley merged commit bd0aa08 into ViewComponent:main Nov 9, 2026
26 checks passed
@czj
czj deleted the rails-9-erb-newline branch November 9, 2026 16:27
@czj

czj commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants