Code Monkey home page Code Monkey logo

view_component-fragment_caching's People

Contributors

cestbalez avatar jequeza avatar patrickarnett avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jequeza cestbalez

view_component-fragment_caching's Issues

Changes to a view component *view file* do not trigger a re-render in rails 7.1

This is linked, as far as I can tell, to this change in rails in ActionView::PathRegistry#cast_file_system_resolvers. As far as I can tell, this only matters in development environment, because the file watcher that triggers re-renders does not really matter in production.

Bug description:

In development, changes to a view component view file (e.g. app/components/some_component.html.erb) do not trigger a re-render. changes to the compoent source code (app/components/some_component.rb) work correctly.

I noticed it with view components that were used inside other templates (e.g. view/some_model/some_mode.html.erb) that were themselves cached, but I think this is not related.

Analysis:

At load time, ViewComponent::FragmentCaching add its resolver to ActionView. This is done in prepend_view_component_paths:

          resolver = Resolvers::ViewComponentResolver.new dir
          context.prepend_view_path resolver

This is needed to add the resolver to ActionView::PathRegistry. Before rails 7.1, adding this resolver triggered the rebuild_watcher callback; after rails 7.1, as ActionView::PathRegistry only calls rebuild_watcher if a new FileSystemResolver had to be built for the added path.

rebuild_watcher is what sets up the filesystem watchers, in ActionView::CacheExpiry::ViewReloader.

Workaround:

Adding the app/view_components path as a regular watch path seems to fix the issue:

# config/initializers/view_component_fragment_caching.rb

ActiveSupport.on_load :action_controller do
  next unless self == ActionController::Base
  
  ActionController::Base.prepend_view_path ::ViewComponent::Base.view_component_path
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.