ViewComponent/view_component · error · ViewComponent::DuplicateContentError
It looks like a block was provided after calling `with_conte
Error message
It looks like a block was provided after calling `with_content` on COMPONENT, which means that ViewComponent doesn't know which content to use. To fix this issue, use either `with_content` or a block.
What it means
Error "It looks like a block was provided after calling `with_content` on COMPONENT, which means that ViewComponent doesn't know which content to use. To fix this issue, use either `with_content` or a block." thrown in ViewComponent/view_component.
Source
Thrown at lib/view_component/base.rb:133
@output_buffer = view_context.output_buffer
@lookup_context = view_context.lookup_context
# For content_for
@view_flow = view_context.view_flow
# For i18n
@virtual_path ||= virtual_path
# Describes the inferred request constraints (locales, formats, variants)
@__vc_requested_details = @lookup_context.vc_requested_details
# For caching, such as #cache_if
@current_template = nil unless defined?(@current_template)
old_current_template = @current_template
if block && defined?(@__vc_content_set_by_with_content)
raise DuplicateContentError.new(self.class.name)
end
@__vc_content_evaluated = false
remove_instance_variable(:@__vc_content) if defined?(@__vc_content)
@__vc_render_in_block = block
@view_context.instance_variable_set(:@virtual_path, virtual_path)
before_render
if render?
value = nil
@output_buffer.with_buffer do
inner_rendered_template = nil
around_rendered_template = around_render do
inner_rendered_template = render_template_for(@__vc_requested_details).to_s
end
View on GitHub (pinned to 9f22c36fa7)
Solutions
- Pass content either with `with_content(value)` or with a render block, but not both: remove the block if you called `with_content`, or remove the `with_content` call if you render with a block.
- Example: render(MyComponent.new) { 'content' } OR render(MyComponent.new.with_content('content')).
When it happens
Trigger: Thrown at lib/view_component/base.rb:133 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of ViewComponent/view_component@9f22c36fa7 (2026-08-23).
Data as JSON: /api/errors/de0238e4b1101b00.
Report an issue: GitHub.