Repository navigation
Render the template for the current format when a lookup context changes formats - #2747
Merged
joelhawksley merged 2 commits intoOct 26, 2026
Merged
Conversation
…ges formats 4.16.0 memoized the Requested details on the LookupContext and never reset the memo. Action Mailer sets `formats` on one lookup context for each part of a multipart email, so components rendered the text template into the HTML part when `format.text` came first. Reuse Action View's `details_key`, which it resets whenever a detail changes.
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.
What are you trying to accomplish?
Updating viewcomponent broke CI for us. The reason is that the cache for vc_requested_details did not work as expected for ActionMailer multipart mails.
#2710 memoizes the Requested details in @__vc_requested_details_cache on the LookupContext and never resets it. Action Mailer's collector sets formats on the mailer's lookup context for each part and renders on that same context, so the first part's formats stick. The implicit-template path (mail without a block) passes formats: to render, which builds a new lookup context, so it isn't affected.
What approach did you choose and why?
vc_requested_details now returns details_key for empty details. With template caching on, details_key is the Requested for the current details, memoized by ActionView::LookupContext and reset by _set_detail whenever a detail changes. It's the same object the previous code read from detail_args_for as from_cache, and returning it directly skips the tuple detail_args_for allocates. With caching off, details_key is nil and the method builds a Requested from the current details.
Anything you want to highlight for special attention from reviewers?
details_key is :nodoc:, so it's undocumented Action View API. RequestDetails already relies on the private detail_args_for, and details_key and _set_detail and this should exist since rails 7.1
I didn't run the tests on the other matrix targets, only on Rails 8.1.4 and Ruby 4.0.6