Module: ViewComponent::CaptureCompatibility
- Defined in:
- lib/view_component/capture_compatibility.rb
Overview
CaptureCompatibility is a module that patches #capture to fix issues related to ViewComponent and functionality that relies on capture like forms, capture itself, turbo frames, etc.
This underlying incompatibility with ViewComponent and capture is that several features like forms keep a reference to the primary ActionView::Base instance which has its own @output_buffer. When #capture is called on the original ActionView::Base instance while evaluating a block from a ViewComponent the @output_buffer is overridden in the ActionView::Base instance, and not the component. This results in a double render due to #capture implementation details.
To resolve the issue, we override #capture so that we can delegate the capture logic to the ViewComponent that created the block.
Defined Under Namespace
Modules: InstanceMethods
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/view_component/capture_compatibility.rb', line 19 def self.included(base) return if base < InstanceMethods base.class_eval do alias_method :original_capture, :capture end base.prepend(InstanceMethods) end |