Skip to content

Commit

Permalink
Fix Rails 7.1 dev-mode template cache (#95)
Browse files Browse the repository at this point in the history
* Make our custom ComponentTemplateResolver view paths work with Rails 7.1 development-mode filesystem template cache
* Make docker compose setup support debugger
  • Loading branch information
patbenatar authored Nov 6, 2023
1 parent b465f66 commit 0692107
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
rbexy (2.0.0.rc2)
rbexy (2.0.0.rc3)
actionview (>= 6, < 7.2)
activesupport (>= 6, < 7.2)

Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ services:
- 3000:3000
environment:
- RAILS_LOG_STDOUT=1
tty: true
stdin_open: true
2 changes: 1 addition & 1 deletion gemfiles/rails_6_1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
rbexy (2.0.0.rc2)
rbexy (2.0.0.rc3)
actionview (>= 6, < 7.2)
activesupport (>= 6, < 7.2)

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7_0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
rbexy (2.0.0.rc2)
rbexy (2.0.0.rc3)
actionview (>= 6, < 7.2)
activesupport (>= 6, < 7.2)

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7_1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
rbexy (2.0.0.rc2)
rbexy (2.0.0.rc3)
actionview (>= 6, < 7.2)
activesupport (>= 6, < 7.2)

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_master.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ GIT
PATH
remote: ..
specs:
rbexy (2.0.0.rc2)
rbexy (2.0.0.rc3)
actionview (>= 6, < 7.2)
activesupport (>= 6, < 7.2)

Expand Down
25 changes: 25 additions & 0 deletions lib/rbexy/rails/engine.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
require "rbexy/rails"
require "action_view/dependency_tracker"

# Rails 7.1 implements development-mode template caching in a way that only works with view paths registered as
# strings with `prepend_view_path`. Since we register our view paths as `ComponentTemplateResolver` instances (which
# are subclasses of Rails `FileSytemResolver`), we have to monkey-patch Rails to make it think our custom resolvers
# are file system resolvers and thus should be supported by its caching mechanism.
if ActionView.version >= Gem::Version.new("7.1")
require "action_view/path_registry"
module ActionView
module PathRegistry
class << self
alias_method :_original_cast_file_system_resolvers, :cast_file_system_resolvers
end

def self.cast_file_system_resolvers(paths)
Array(paths).each do |path|
next unless path.is_a?(Rbexy::Rails::ComponentTemplateResolver)
@file_system_resolvers[path] ||= path
file_system_resolver_hooks.each(&:call)
end

_original_cast_file_system_resolvers(paths)
end
end
end
end

module Rbexy
module Rails
class Engine < ::Rails::Engine
Expand Down

0 comments on commit 0692107

Please sign in to comment.