view_component: ViewComponent::Base.config.view_component_path nil error
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.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 3
- Comments: 16 (1 by maintainers)
@reeganviljoen @boardfish sorry for the late reply. it resolves my issues too! thanks
@GyozaGuy @Spone @boardfish this pr seems to have caused the issue https://github.com/ViewComponent/view_component/pull/1659
Great to hear it, and no problem!
Yep that’s working now! Thanks for your work on this!
@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!
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.
@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!
@thank you @GyozaGuy I see
@boardfish mind looking into this?