Skip to content

Commit

Permalink
Access view_context from Phlex::Context instead of SGML ivar
Browse files Browse the repository at this point in the history
  • Loading branch information
willcosgrove committed Nov 9, 2024
1 parent 80388e7 commit 30eab4e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/phlex/rails/sgml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ def render_in(...)

module Overrides
def helpers
if defined?(ViewComponent::Base) && ViewComponent::Base === @_view_context
@_view_context.helpers
view_context = @_context.view_context

if defined?(ViewComponent::Base) && ViewComponent::Base === view_context
view_context.helpers
else
@_view_context
view_context
end
end

Expand All @@ -33,23 +35,23 @@ def render(*args, **kwargs, &block)

if partial # this is a hack to get around https://github.com/rails/rails/issues/51015
return raw(
@_view_context.render(partial, **kwargs) do |*yielded_args|
@_context.view_context.render(partial, **kwargs) do |*yielded_args|
capture(*yielded_args, &block)
end,
)
end
end

output = if block
@_view_context.render(*args, **kwargs) do |*yielded_args|
@_context.view_context.render(*args, **kwargs) do |*yielded_args|
if yielded_args.length == 1 && defined?(ViewComponent::Base) && ViewComponent::Base === yielded_args[0]
capture(Phlex::Rails::Buffered.new(yielded_args[0], view: self), &block)
else
capture(*yielded_args, &block)
end
end
else
@_view_context.render(*args, **kwargs)
@_context.view_context.render(*args, **kwargs)
end

raw(output)
Expand Down

0 comments on commit 30eab4e

Please sign in to comment.