Skip to content

[3.x] Add a failing test for rendering a partial inside a collection rendering - #2674

Merged
joelhawksley merged 5 commits into
ViewComponent:3.xfrom
jcoyne:collection-rendering
Aug 12, 2026
Merged

[3.x] Add a failing test for rendering a partial inside a collection rendering#2674
joelhawksley merged 5 commits into
ViewComponent:3.xfrom
jcoyne:collection-rendering

Conversation

@jcoyne

@jcoyne jcoyne commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

What are you trying to accomplish?

This is a bug report, of a regression in 3.25 (from 3.24).

We get this error when rendering a partial from within a rendered component:

NoMethodError: undefined method 'render' for nil
    lib/view_component/base.rb:228:in 'ViewComponent::Base#render'
    test/sandbox/test/collection_test.rb:35:in '...PartialRenderingComponent#call'
    lib/view_component/collection.rb:22:in 'block in ViewComponent::Collection#render_in'
    lib/view_component/test_helpers.rb:54:in 'ViewComponent::TestHelpers#render_inline'

I believe this was introduced by ce1c920

on this line here: ce1c920#diff-b69c75ffd85596e0b5fca1327059ecf3b2930f3f77004c78a268fa85e8ec8d9eL83

The old ||= silently masked a nil. The new code keys off instance_variable_defined?, so an explicitly-stashed nil is now honored.

I think we can fix this by adding:

(remove_instance_variable(...) || view_context

at base.rb:91.

@joelhawksley
joelhawksley merged commit b51de2c into ViewComponent:3.x Aug 12, 2026
28 checks passed
@joelhawksley joelhawksley mentioned this pull request Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants