-
Notifications
You must be signed in to change notification settings - Fork 445
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
TypeError: no implicit conversion of nil into String #1565
Comments
I think the change to I'm surprised that the tests that maintain compatibility between There's an interesting problem here. Rails' own config is the user's endpoint for making config changes, but |
We're also seeing this problem with the Blacklight Rails engine. |
Thanks for the digging @boardfish! We (from a gem perspective) are also happy to try to build on top of ViewComponent a different way if that might lead to a better future / less complexity from your side. I'm just not sure how that might look at the moment. 🤔 |
Hm, sorry for the issues - I don't think I considered loading this outside of Rails. I'll try and take a look at this sometime next week, if noone else beats me to it. |
I found that I can resolve this problem by adding this to my engine's base component class: def self.inherited(subclass)
subclass.config = ViewComponent::Base.config
super
end |
Thanks for sharing @jcoyne .. I'm not having as much luck (looking into what I'm doing differently). require "view_component"
require "ahoy_matey"
class ApplicationComponent < ViewComponent::Base
include ActiveModel::Validations
# workaround for https://github.com/ViewComponent/view_component/issues/1565#issuecomment-1302397965
class << self
def inherited(subclass)
subclass.config = ViewComponent::Config.new
super
end
end
end For me it still blows up on |
I think one possible easy fix is like this - diff --git a/lib/view_component/base.rb b/lib/view_component/base.rb
index f1bc391..11f712a 100644
--- a/lib/view_component/base.rb
+++ b/lib/view_component/base.rb
@@ -20,7 +20,7 @@ module ViewComponent
delegate(*ViewComponent::Config.defaults.keys, to: :config)
def config
- @config ||= ActiveSupport::OrderedOptions.new
+ @config ||= ViewComponent::Config.defaults
end
attr_writer :config
end Then both Rails.application.config.view_component and VC::Base.config will default to the values in VC::Config.defaults. Will try and add some tests demoing the empty config outside of rails. |
Hm, I think the above fix is fine for the simple case as long as matey/blacklight/etc don't need to mess with ViewComponent config. If they do try and set, eg, ViewComponent::Base.config.view_component_path, that'll get lost after Rails initialization completes here - https://github.com/github/view_component/blob/fa83442646eff70f1801d6885a3fc8c430a1ce68/lib/view_component/engine.rb#L39 |
@jdelStrother thanks! Just confirming that this change does indeed make I don't foresee (instantly jinxed) us modifying any of the base configurations as they exist today. In the event we did, might a Rails initializer work (I can try this later today)? |
If the Railtie initialization hasn't yet run (or if it won't run at all because it's being used outside of a Rails app), and a gem tries to subclass ViewComponent::Base, it would fail in Base.inherited due to config.view_component_path being nil. Fixes ViewComponent#1565
If the Railtie initialization hasn't yet run (or if it won't run at all because it's being used outside of a Rails app), and a gem tries to subclass ViewComponent::Base, it would fail in Base.inherited due to config.view_component_path being nil. Fixes ViewComponent#1565
I have the same error on version 3.0.0 when a gem uses view_component.
To fix it I surrounded that code with So it becames if defined?(Rails) && Rails.application
child.virtual_path = child.source_location.gsub(
/(.*#{Regexp.quote(ViewComponent::Base.config.view_component_path)})|(\.rb)/, ""
)
end |
Closed by #1738 |
Thanks for all of your work on 2.75.0! Our gem seems to be less appreciative though...
We are hitting an issue with 2.75.0 causing
TypeError: no implicit conversion of nil into String
in our matey gem. The problem does not occur in 2.74.1.For some reason in
base.rb
ViewComponent::Base.config.view_component_path
is nil which causesRegex.quote
to throw an exception. Upon a little further inspection, the whole config object is empty:If I add something like the following above
base.rb#509
it seems to work :-)I'm still digging around but wanted to post in case others are experiencing the same issue.
Steps to reproduce
Expected behavior
Expect the test cases to pass as with 2.74.1
Actual behavior
Test cases are not happy!
System configuration
Rails version: 7.0.4
Ruby version: ruby 3.1.2p20
Gem version: 2.75.0
The text was updated successfully, but these errors were encountered: