-
Notifications
You must be signed in to change notification settings - Fork 488
Expire memoized template digests when a component registers #2709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
joelhawksley
merged 1 commit into
ViewComponent:main
from
erikaxel:vc-digest-registration-invalidates-cache
Sep 24, 2026
+81
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I don't think this should be fixed:
Below is a longer explanation of what we would need to do to fix it. Let me know what you decide.
When it can produce a wrong digest. Only while the feature is switching on: the first cacheable component registering while another thread is mid-digest. Once the registry is non-empty, DependencyTracking scans every template, and constantize_component autoloads any component it finds before returning its path. By the time a path is in the tree its component has registered, so an in-flight digest that straddles a later registration is already correct, and memoizing it after the clear is harmless.
Why not take the Digestor’s lock. register runs from included/inherited, during an autoload, while Ruby holds the require lock for that file. A digesting thread holds the digest mutex and, once the tracker is installed, may safe_constantize the same component and block on that require lock, so the two threads wait on each other. On a single thread, the scan’s own autoload re-enters register while the mutex is already held, which raises ThreadError. The mutex is also private and has changed shape (@@digest_mutex through 8.1, a Ractor-local digest_mutex on main).
Closing it fully would mean wrapping ActionView::Digestor.digest with a registry generation check and retry, installed at boot for every app rather than on the first include. A thread already inside digest when the first component loads would never pass through a wrapper installed later. That runs against the current design, where nothing is installed until a component opts in, so I’ve left it out. Happy to add it if you’d prefer the stronger guarantee.