ViewComponent / view_component

A framework for building reusable, testable & encapsulated view components in Ruby on Rails.
https://viewcomponent.org
MIT License
3.31k stars 433 forks source link

Annotations missing for inline components when annotate_rendered_view_with_filenames is enabled #1301

Open dmarcoux opened 2 years ago

dmarcoux commented 2 years ago

I am using view_component in a Rails application with config.action_view.annotate_rendered_view_with_filenames set to true. For view components with templates, the HTML is annotated with the usual BEGIN and END. However for inline components (so relying on call and not having a template), the HTML doesn't contain those annotations.

Steps to reproduce

  1. Set config.action_view.annotate_rendered_view_with_filenames set to true in your Rails config.
  2. Render a view component with a template.
  3. Render an inline view component.
  4. See the BEGIN and END comments for the view component with a template, but not for the inline view component.

Example in which the <abbr> tag is an inline view component and another component with a template which renders Hello!: example

Expected behavior

I expect the annotations to be added for inline view components.

Actual behavior

The annotations are not added for inline view components.

System configuration

Rails version: Rails 7.0.2.2

Ruby version: ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-linux]

Gem version: 2.49.1

joelhawksley commented 2 years ago

@dmarcoux thanks for filing this issue! The current implementation of template annotations hooks into the template compilation process, which isn't used for inline components.

I'd love to see this feature added to the framework, would you like to take it on? I'd be happy to pair with you to get it off the ground: joelhawksley@github.com

joevandyk commented 1 month ago

would love to have this - would this be done via output_postamble and output_preamble?

joelhawksley commented 1 month ago

@joevandyk yes, I think we'd do it in that area of the codebase! Happy to pair with you if you'd like, email me with your availability if you'd like: joelhawksley@github.com