Open omarluq opened 1 year ago
P.S I can fix the issue by adding data-reflex-permanent tags on a div a wrap the trigger and the sections with it but is that an optimal solution?
@julianrubisch @joshleblanc any ideas?
I talked with Omar awhile ago, and I think he found a workaround. Leaving this open because I'm pretty sure it's still a bug.
After you agreed to whitelist the cable_ready helper on the components I ended up switching the page morphs
to add_css_class
and remove_css_class
. Another fix that I found at the time was using printing tags when calling the with_slot_name
helper ex:
<%= render(Component.new) do |c|%>
<%= c.with_slot %>
<% end %>
But the ViewComponent docs recommend using non-printing tags for slots!
I see slots are currently still not supported, as ViewComponentReflex ignores any @__vc
instance variable.
I assume that's because it's problematic to serialize/deserialize them:
def safe_instance_variables
instance_variables.reject { |ivar| ivar.start_with?("@__vc") } - unsafe_instance_variables - omitted_from_state
end
My quick workaround:
partial
file
component.with_xxxx
methodsExample:
# my_component.rb
class MyComponent < ApplicationViewComponent
renders_one :hello_world
def initialize(partial_path:, other_state: {})
@partial_path = partial_path
@other_state = other_state
end
def before_render
super
render partial: @partial_path, locals: { component: self } if @partial_path
end
end
- # my_component.html.haml
= hello_world
- # show.html.haml
= render MyComponent.new(partial_path: '_partial_component_content', other_state: {})
- # _partial_component_content.html.haml
- component.with_hello_world do
Hello world!
@Laykou I think that this workaround is very similar to using printing tags to call your slots, both solutions force a recall of the slots block on every refresh pretty much
In my app I have the following dropdown menu component when the open function is triggered the menu component is losing all of its slots, am I missing something? I've never encountered this issue before