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 鈥淪ign up for GitHub鈥, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fragment Caching POC #980
base: main
Are you sure you want to change the base?
Fragment Caching POC #980
Conversation
|
ops. |
672d38b
to
63a08f8
Compare
|
This feature set is super exciting. Curious about the monkey patch - Are these changes that could reasonably be a part of Rails itself? Could we eliminate the monkey patch entirely and make this just about registering trackers? |
Joel said the exact same thing
I think it won't work without some changes to |
|
I started working on this in a Rails 6.0 app, but there's a couple of things that are slightly broken in 6.1+. I'll push some fixes shortly and add some initial tests. |
982ff49
to
618354f
Compare
|
If anyone's interested what the |
Some of the changes around the introduction of ActionView::PathParser and ActionView::Template::Types in 6.1 meant component files were more difficult to find here...
Fixes static dependency tracking for 6.1+, where some minor breaking changes to the arguments of #add_static_dependency were introduced. Should be backwards-compatible with =< 6.0.
The MatchData object returned by Regexp#last_match throws an error if an undefined group is requested. In the case where layout dependencies are passed to #add_dependencies, the :component match group will not exist. MatchData#named_captures returns a simpler Hash which returns nil for undefined groups instead of raising.
The engine fails to use the correct paths in the test environment without this, and looks in the root of the repo instead of the dummy app.
There were several breaking changes to digests between Rails 5.2 and 6.0 which are not compatible
|
I had a go at reformulating this as a PR on ActionView and it looks a lot better. Preview here. |
|
@Matt-Yorkley Any progress on this? Are you planning on making a PR to ActionView for that change? |
Yes and no. I did make that PR, but it was rejected: rails/rails#42850 If anyone else wants to take up the baton on this one, be my guest. |
|
We took a really similar approach to this in setting up a VC fragment caching gem which we are evaluating in our code base. I was let down to see the hard no on extending how rails template lookups work, but I think this approach can work without causing too much unintended The gem we're doing this work on lives here, and the current PR is what we are seeing some success with in our code at G2. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Summary
This is a rough draft POC to explore adding compatibility for Fragment Caching in ViewComponent.
It makes some modifications to
ActionView::DigestorandActionView::ERBTrackerin order to get digests working correctly with components, which means (for example) if you cache a rails view that renders a component inside it and the contents of the component class file change, the digest used in the cache key will be updated and the cached fragment will be correctly invalidated.Initial notes in issue #476 (comment)
Current state: