-
Notifications
You must be signed in to change notification settings - Fork 422
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
ViewComponent::Base.config.view_component_path nil error #1741
Comments
@geekdreamzz so https://github.com/ViewComponent/view_component/blob/main/lib/view_component/base.rb#L289 explains why it is nil in your case, hear is the line for reference:
|
If you want to use a parent component generate a component with this |
I'm seeing this error as well as of today after updating my gems. @reeganviljoen your explanation makes sense, but the app won't even run without manually setting the config. |
@boardfish mind looking into this? |
@GyozaGuy @Spone @boardfish this pr seems to have caused the issue #1659 |
@donapieppo this pr #1659 moved all config defaults out of the base class so any path configs dont work in 3.0 unless you specify them yourself |
@geekdreamzz @GyozaGuy #1774 may fix your issue. Could you give it a shot by updating your Gemfile to point at that branch of this repo? Thanks! |
I'm no longer getting the original error, but this new one is now happening:
|
Thanks! This looks familiar – I got the same thing when I reverted the original PR that fixed the load order, so that sort of signalled this. I'll update that PR in a bit and let you know in this thread. It's probably best just to get this fixed for now, but if there's a way we can emulate the inclusion of the gem in an environment where Rails hasn't loaded such that we prevent this from breaking in future, I'm interested in getting that sorted. I hope we can continue to allow folks to extend off ViewComponent via gems. |
@GyozaGuy It's now been updated to only include the URL helpers if the Rails app has been loaded. You're welcome to give that a try whenever you're ready! |
Yep that's working now! Thanks for your work on this! |
Great to hear it, and no problem! |
@geekdreamzz do you have any updates on this issue |
@reeganviljoen @boardfish sorry for the late reply. it resolves my issues too! thanks |
Hi - I recently updated to 3.0.0 and suddenly started getting this error on all my components:
ActionView::Template::Error (no implicit conversion of nil into String)
When I go into the stack trace I see it errors out at https://github.com/ViewComponent/view_component/blob/main/lib/view_component/base.rb#L452
Regexp.quote(ViewComponent::Base.config.view_component_path)
I'm not sure what ViewComponent::Base.config.view_component_path is for? but it's nil for me and this Regexp.quote method throws the error.
To get back up and running I just set ViewComponent::Base.config.view_component_path = '' and I'm good, but it's clearly a workaround.
TBH, I'm not sure if I'm using the gem the intended way but I essentially create my own classes that inherit from ViewComponent::Base. I could send a PR to account for nil ViewComponent::Base.config.view_component_path but it would just mask the issue. I'm a bit out of my wheelhouse trying to debug the underlying issue, I'm not able to follow what the comments here imply:
# Removes the first part of the path and the extension. child.virtual_path = child.source_location.gsub( /(.*#{Regexp.quote(ViewComponent::Base.config.view_component_path)})|(\.rb)/, "" )
I'd be happy to contribute to the gem if you want to give some feedback on what ViewComponent::Base.config.view_component_path is for and what child.virtual_path is designed for.
My base class that inherits from ViewComponent::Base also has a config so it's prob something dumb on my end. You could also just disregard this but figured I share the error in case it happens to anyone else.
The text was updated successfully, but these errors were encountered: