-
Notifications
You must be signed in to change notification settings - Fork 433
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
Error when using .css.erb
sidecar file for component
#1783
Comments
Hi @fredboyle thanks for opening an issue to report this bug. Would you like to open a PR with a failing test that reproduces the issue? A good starting point would be to duplicate and adapt this existing test:
|
@Spone That test is the failing issue. I'm not clear on what more you would like. If you add more than one file in the sidecar directory with a Does that help? |
@fredboyle the problem is when you add another erb file in the sidecar it looks it attempts to handke it like a component template but view component only supports the HTML format currently as well as one templste per component, their is however an issue discussing this |
@reeganviljoen Could you link me to that discussion please? The root issue, to me, it appears is that the concept of a ViewComponent template is far too broad and basically is anything with a |
@fredboyle here is the discussion #1768 |
Thanks for the link @reeganviljoen. I dug into the ViewComponent code and found that perhaps adding a config setting might be suitable, at least in the interim. Here's a hastily hacked alteration of the def templates
@templates ||=
begin
extensions = ActionView::Template.template_handler_extensions
# This would be a ViewComponent config setting to list extensions to NOT be considered view templates for the component
# - perhaps named "excluded_view_template_extensions"
ignore_extensions = ["css", "js"]
component_class.sidecar_files(extensions).each_with_object([]) do |path, memo|
pieces = File.basename(path).split(".")
memo << {
path: path,
variant: pieces[1..-2].join(".").split("+").second&.to_sym,
handler: pieces.last
} unless ignore_extensions.include?(pieces.second)
# line above adds the qualifier for being added to the list of templates
# - exclude any file found that matches the exclusion list
end
end
end It appears the root cause here is that the However in the case of ViewComponent and the definition of a "template" we do care as not all files are the same. Only those of valid HTML output type are of import for rendering a proper component. Therefore ViewComponent should have a mechanism to better define and use only valid template files, regardless of the processor a file may use. Perhaps ViewComponent should by default only seek out a For now the above example of altering the Thoughts? |
@joelhawksley would we be able to differentiate between assets and templates with erb extension inside the compiler |
That's the approach I'd take. |
Following up for my clarity. Will this be worked on for an upcoming version/release? Should I attempt a pull-request? Or should another approach be taken to help expedite this and/or keep it moving in a forward direction? Thanks for your help. |
Sorry @fredboyle i have had a really busy workload the past 2 months so I diddnt get to see this, I was wandering if @joelhawksley if you could provide an overview of how the compiler works sk I cam get started on something |
Hey @reeganviljoen, @joelhawksley is away until November, but I'm happy to help with this issue. I would definitely welcome a pull request, who'd like to take it on? The compiler identifies sidecar templates, i.e. templates that live in a directory with the same name as the component. For each sidecar template, the compiler calls the I think @fredboyle identified the right place to introduce a config option and filter out templates that shouldn't be compiled, although |
@fredboyle any appetite to take this on and submit a PR? |
@camertron I'll take a look and see what I can come up with. No promises regarding timeline but I'll take a stab at it when I can. |
See pull-request #1990 to hopefully address this discussion. |
Steps to reproduce
.css.erb
file to the component's sidecar directoryExpected behavior
ViewComponent should only look for
.html.erb
files for templates. If more than one HTML file is found produce error, otherwise carry on.Actual behavior
Error: "More than one template found" was received when another
.erb
file is in the component's sidecar directory.Backtrace:
System configuration
Rails version:
7.0.5
Ruby version:
3.2.2
Gem version:
3.2.0
The text was updated successfully, but these errors were encountered: