Skip to content
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

Open
fredboyle opened this issue Jun 24, 2023 · 14 comments
Open

Error when using .css.erb sidecar file for component #1783

fredboyle opened this issue Jun 24, 2023 · 14 comments
Labels
bug Something isn't working help wanted

Comments

@fredboyle
Copy link

Steps to reproduce

  1. Generate a new component with sidecar files
  2. Add a .css.erb file to the component's sidecar directory
  3. Attempt to view the preview of the component
  4. Result: Error "More than one template found"

Expected 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:

[view_component (3.2.0) lib/view_component/compiler.rb:36:in `compile' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[view_component (3.2.0) lib/view_component/base.rb:479:in `compile' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[view_component (3.2.0) lib/view_component/base.rb:72:in `render_in' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionview (7.0.5) lib/action_view/helpers/rendering_helper.rb:42:in `render' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[view_component (3.2.0) app/views/view_components/preview.html.erb:3 ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionview (7.0.5) lib/action_view/base.rb:244:in `public_send' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionview (7.0.5) lib/action_view/base.rb:244:in `_run' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionview (7.0.5) lib/action_view/template.rb:157:in `block in render' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activesupport (7.0.5) lib/active_support/notifications.rb:208:in `instrument' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionview (7.0.5) lib/action_view/template.rb:361:in `instrument_render_template' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionview (7.0.5) lib/action_view/template.rb:155:in `render' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionview (7.0.5) lib/action_view/renderer/template_renderer.rb:65:in `block (2 levels) in render_template' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activesupport (7.0.5) lib/active_support/notifications.rb:206:in `block in instrument' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activesupport (7.0.5) lib/active_support/notifications/instrumenter.rb:24:in `instrument' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activesupport (7.0.5) lib/active_support/notifications.rb:206:in `instrument' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionview (7.0.5) lib/action_view/renderer/template_renderer.rb:60:in `block in render_template' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionview (7.0.5) lib/action_view/renderer/template_renderer.rb:75:in `block in render_with_layout' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activesupport (7.0.5) lib/active_support/notifications.rb:206:in `block in instrument' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activesupport (7.0.5) lib/active_support/notifications/instrumenter.rb:24:in `instrument' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activesupport (7.0.5) lib/active_support/notifications.rb:206:in `instrument' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionview (7.0.5) lib/action_view/renderer/template_renderer.rb:74:in `render_with_layout' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionview (7.0.5) lib/action_view/renderer/template_renderer.rb:59:in `render_template' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionview (7.0.5) lib/action_view/renderer/template_renderer.rb:11:in `render' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionview (7.0.5) lib/action_view/renderer/renderer.rb:61:in `render_template_to_object' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionview (7.0.5) lib/action_view/renderer/renderer.rb:29:in `render_to_object' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionview (7.0.5) lib/action_view/rendering.rb:117:in `block in _render_template' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionview (7.0.5) lib/action_view/base.rb:270:in `in_rendering_context' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionview (7.0.5) lib/action_view/rendering.rb:116:in `_render_template' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_controller/metal/streaming.rb:216:in `_render_template' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionview (7.0.5) lib/action_view/rendering.rb:103:in `render_to_body' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_controller/metal/rendering.rb:158:in `render_to_body' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_controller/metal/renderers.rb:141:in `render_to_body' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/abstract_controller/rendering.rb:27:in `render' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_controller/metal/rendering.rb:139:in `render' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_controller/metal/instrumentation.rb:22:in `block (2 levels) in render' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[/Users/FredBoyle/.rubies/ruby-3.2.2/lib/ruby/3.2.0/benchmark.rb:311:in `realtime' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activesupport (7.0.5) lib/active_support/core_ext/benchmark.rb:14:in `ms' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_controller/metal/instrumentation.rb:22:in `block in render' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_controller/metal/instrumentation.rb:91:in `cleanup_view_runtime' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activerecord (7.0.5) lib/active_record/railties/controller_runtime.rb:34:in `cleanup_view_runtime' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_controller/metal/instrumentation.rb:21:in `render' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[view_component (3.2.0) app/controllers/concerns/view_component/preview_actions.rb:42:in `previews' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/abstract_controller/base.rb:215:in `process_action' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_controller/metal/rendering.rb:165:in `process_action' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/abstract_controller/callbacks.rb:234:in `block in process_action' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activesupport (7.0.5) lib/active_support/callbacks.rb:118:in `block in run_callbacks' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[i18n (1.14.1) lib/i18n.rb:322:in `with_locale' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[view_component (3.2.0) app/controllers/concerns/view_component/preview_actions.rb:72:in `set_locale' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activesupport (7.0.5) lib/active_support/callbacks.rb:127:in `block in run_callbacks' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actiontext (7.0.5) lib/action_text/rendering.rb:20:in `with_renderer' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actiontext (7.0.5) lib/action_text/engine.rb:69:in `block (4 levels) in <class:Engine>' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activesupport (7.0.5) lib/active_support/callbacks.rb:127:in `instance_exec' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activesupport (7.0.5) lib/active_support/callbacks.rb:127:in `block in run_callbacks' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activesupport (7.0.5) lib/active_support/callbacks.rb:138:in `run_callbacks' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/abstract_controller/callbacks.rb:233:in `process_action' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_controller/metal/rescue.rb:22:in `process_action' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_controller/metal/instrumentation.rb:67:in `block in process_action' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activesupport (7.0.5) lib/active_support/notifications.rb:206:in `block in instrument' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activesupport (7.0.5) lib/active_support/notifications/instrumenter.rb:24:in `instrument' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activesupport (7.0.5) lib/active_support/notifications.rb:206:in `instrument' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_controller/metal/instrumentation.rb:66:in `process_action' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_controller/metal/params_wrapper.rb:259:in `process_action' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activerecord (7.0.5) lib/active_record/railties/controller_runtime.rb:27:in `process_action' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/abstract_controller/base.rb:151:in `process' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionview (7.0.5) lib/action_view/rendering.rb:39:in `process' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_controller/metal.rb:188:in `dispatch' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_controller/metal.rb:251:in `dispatch' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/routing/route_set.rb:49:in `dispatch' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/routing/route_set.rb:32:in `serve' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/journey/router.rb:50:in `block in serve' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/journey/router.rb:32:in `each' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/journey/router.rb:32:in `serve' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/routing/route_set.rb:852:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/middleware/static.rb:23:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[rack (2.2.7) lib/rack/tempfile_reaper.rb:15:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[rack (2.2.7) lib/rack/etag.rb:27:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[rack (2.2.7) lib/rack/conditional_get.rb:27:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[rack (2.2.7) lib/rack/head.rb:12:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/http/permissions_policy.rb:38:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/http/content_security_policy.rb:36:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[rack (2.2.7) lib/rack/session/abstract/id.rb:266:in `context' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[rack (2.2.7) lib/rack/session/abstract/id.rb:260:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/middleware/cookies.rb:704:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activerecord (7.0.5) lib/active_record/migration.rb:603:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activesupport (7.0.5) lib/active_support/callbacks.rb:99:in `run_callbacks' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/middleware/callbacks.rb:26:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/middleware/executor.rb:14:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/middleware/debug_exceptions.rb:28:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/middleware/show_exceptions.rb:26:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[railties (7.0.5) lib/rails/rack/logger.rb:40:in `call_app' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[railties (7.0.5) lib/rails/rack/logger.rb:25:in `block in call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activesupport (7.0.5) lib/active_support/tagged_logging.rb:99:in `block in tagged' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activesupport (7.0.5) lib/active_support/tagged_logging.rb:37:in `tagged' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activesupport (7.0.5) lib/active_support/tagged_logging.rb:99:in `tagged' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[railties (7.0.5) lib/rails/rack/logger.rb:25:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[sprockets-rails (3.4.2) lib/sprockets/rails/quiet_assets.rb:13:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/middleware/remote_ip.rb:93:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/middleware/request_id.rb:26:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[rack (2.2.7) lib/rack/method_override.rb:24:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[rack (2.2.7) lib/rack/runtime.rb:22:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[activesupport (7.0.5) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/middleware/server_timing.rb:61:in `block in call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/middleware/server_timing.rb:26:in `collect_events' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/middleware/server_timing.rb:60:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/middleware/executor.rb:14:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/middleware/static.rb:23:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[rack (2.2.7) lib/rack/sendfile.rb:110:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[actionpack (7.0.5) lib/action_dispatch/middleware/host_authorization.rb:137:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[railties (7.0.5) lib/rails/engine.rb:530:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[puma (6.3.0) lib/puma/configuration.rb:270:in `call' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[puma (6.3.0) lib/puma/request.rb:100:in `block in handle_request' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[puma (6.3.0) lib/puma/thread_pool.rb:344:in `with_force_shutdown' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[puma (6.3.0) lib/puma/request.rb:99:in `handle_request' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[puma (6.3.0) lib/puma/server.rb:443:in `process_client' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
[puma (6.3.0) lib/puma/server.rb:245:in `block in run' ](http://127.0.0.1:3001/dev/components/zest/checkbox_component/default#)
puma (6.3.0) lib/puma/thread_pool.rb:151:in `block in spawn_thread'

System configuration

Rails version:
7.0.5

Ruby version:
3.2.2

Gem version:
3.2.0

@Spone
Copy link
Collaborator

Spone commented Jun 26, 2023

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:

def test_raises_error_when_more_than_one_sidecar_template_is_present

@fredboyle
Copy link
Author

@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 .erb extension the test fails. The reality should be that only multiple .html.erb files should trigger this failure.

Does that help?

@reeganviljoen
Copy link
Collaborator

reeganviljoen commented Jun 27, 2023

@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

@fredboyle
Copy link
Author

@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 .erb extension. I feel it should be more precise in order to better follow the concept of a component – a thing with a logic definition (.rb), a rendering template (HTML / .html.erb) , and supporting files (images, CSS, JS, etc).

@reeganviljoen
Copy link
Collaborator

@fredboyle here is the discussion #1768

@fredboyle
Copy link
Author

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 templates method in compiler.rb:

    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 ActionView::Template.template_handler_extensions only considers the handler/parser and not the type of file being parsed, this makes sense since the handler doesn't care.

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 .html or .html.* file as the template or templates, but also allow a user override via config to include others or alternatives.

For now the above example of altering the template method of compiler.rb should prove sufficient for common simple cases and avoid breaking ViewComponent in the process.

Thoughts?

@reeganviljoen
Copy link
Collaborator

@joelhawksley would we be able to differentiate between assets and templates with erb extension inside the compiler

@reeganviljoen reeganviljoen added bug Something isn't working help wanted labels Jul 1, 2023
@joelhawksley
Copy link
Member

Perhaps ViewComponent should by default only seek out a .html or .html.* file as the template or templates, but also allow a user override via config to include others or alternatives.

That's the approach I'd take.

@fredboyle
Copy link
Author

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.

@reeganviljoen
Copy link
Collaborator

reeganviljoen commented Aug 16, 2023

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

@camertron
Copy link
Contributor

camertron commented Aug 23, 2023

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 #compile_template method, which passes the contents of the template to the template handler. The handler returns a chunk of Ruby code which the compiler subsequently wraps in def call and class_evals on the component class. When #call is invoked, it renders the template to the current output buffer using a series of #append= and #safe_append= calls.

I think @fredboyle identified the right place to introduce a config option and filter out templates that shouldn't be compiled, although ActionView::Template.template_handler_extensions does not include css or js. You'd have to first strip off the template handler extension (i.e. .erb) and then use File.extname to determine if the file should be ignored or not.

@camertron
Copy link
Contributor

@fredboyle any appetite to take this on and submit a PR?

@fredboyle
Copy link
Author

@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.

@fredboyle
Copy link
Author

See pull-request #1990 to hopefully address this discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted
Projects
None yet
Development

No branches or pull requests

5 participants