-
Notifications
You must be signed in to change notification settings - Fork 444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Components with only variant template crashes the app #1956
Comments
@sigra the reason you get this error is because you aren't using a variant in your request so the component will not be rendered with a variant, and in that case it needs a default template without a variant, if you dont want the component to render without a variant, try doing a check on the variant in the |
Thanks for the diagnosis, @reeganviljoen! Knowing this, we could start returning a helpful error here with similar advice to what you've provided just there. |
@boardfish I can get that working when I get some time |
Thanks for reply, @reeganviljoen . Patching the class ExampleComponent < ApplicationComponent
def render?
raise 'Unreachable code'
end
end Rails console output:
Backtrace:
I know that I can create empty As for me the most obvious way is to check is method view_component/lib/view_component/compiler.rb Lines 300 to 303 in c8462c2
Suggested fix: if call_defined?
component_class.define_method(:"_call_#{safe_class_name}", component_class.instance_method(:call))
end |
@sigra we really appreciate your debug samples and reproduction, this will certainly help, would you be able to write a failing test for this situation so someone can use that as a guideline to fix this bug ? |
@reeganviljoen will be it enough? sigra@0b80539
|
@sigra this is a big help thank you |
I've started to upgrade from 3.2.0 to 3.9.0 and my application stopped launching. Downgrading version by version I found that the issue starts from 3.5.0.
The app crashes with the error like:
My component doesn't have template without variant and I sure it's an issue. Seems that
Compiler#define_render_template_for
expects that component class always has:call
method defined:view_component/lib/view_component/compiler.rb
Line 104 in 3487283
But this method isn't defined because my component has only "variant" template:
view_component/lib/view_component/compiler.rb
Lines 69 to 82 in 3487283
Steps to reproduce
System configuration
Rails version:
6.1.7.5
Ruby version:
3.2.2
Gem version:
3.5.0
The text was updated successfully, but these errors were encountered: