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

Fragment caching an erb template with a Phlex component complains it can't digest template #106

Closed
davidalejandroaguilar opened this issue Sep 1, 2023 · 2 comments

Comments

@davidalejandroaguilar
Copy link
Contributor

davidalejandroaguilar commented Sep 1, 2023

Expected Behavior

Read fragment views/tests/index:06ce85b70ee7a70c70923bcbbff4dc2d/1693531182 (0.1ms)
Write fragment views/tests/index:06ce85b70ee7a70c70923bcbbff4dc2d/1693531182 (0.1ms)

Actual behavior

  Couldn't find template for digesting: news/new
Read fragment views/tests/index:06ce85b70ee7a70c70923bcbbff4dc2d/1693531182 (0.1ms)
Write fragment views/tests/index:06ce85b70ee7a70c70923bcbbff4dc2d/1693531182 (0.1ms)

How to reproduce

  1. Enable dev caching
rails dev:cache
  1. Add a component
class TestComponent < ApplicationComponent
  def template
    plain "hi"
  end
end
  1. Render it within a Rails view
class TestsController < ApplicationController
  def index
  end
end
<%= cache Time.current.to_i do %>
  <%= render TestComponent.new %>
<% end %>
  1. Refresh the page and check the logs

  2. Modify the template

<%= cache Time.current.to_i do %>
  something new
  <%= render TestComponent.new %>
<% end %>
  1. Refresh the page and check the logs
@davidalejandroaguilar davidalejandroaguilar changed the title Fragment caching an erb template with a Phlex component is not working Fragment caching an erb template with a Phlex component complains it can't digest template Sep 1, 2023
@joeldrapper
Copy link
Collaborator

Thanks for opening this as a separate issue. I’d like to try to fix this one, since compatibility with existing ERB is essential.

@joeldrapper
Copy link
Collaborator

@davidalejandroaguilar I’ve looked into this and confirmed the problem. It looks like Rails builds up a dependency tree by parsing the ERB files and finding render calls. It only does this when rendering partials.

For Phlex to fit in here, Rails would have to parse render calls to objects, e.g. render Foo.new and then establish an interface that the class can implement to be a part of the dependency tree.

Here’s a link to the current parser. https://github.com/rails/rails/blob/main/actionview/lib/action_view/render_parser/prism_render_parser.rb

We would be happy to implement a class method on our renderable classes if that was supported by Rails.

I think the best way forward is to bring this up in a new Rails issue. You can mention this issue and this one from ViewComponent. ViewComponent/view_component#234

For now, I’m going to close this as there’s nothing we can do here until something changes in Rails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants