Skip to content

Commit 763941e

Browse files
Always provide a fallback renderer for Action Text
Follow-up to rails#45144. This ensures that a renderer is always available for Action Text, even when `ActionController::Base` was not previously loaded. Fixes rails#46113. As with rails#45144, this still avoids loading `ActionController::Base` unnecessarily when rendering mail after Action Text has been loaded. **Before:** ``` $ bin/rails r 'Benchmark.memory { |x| x.report("load"){ MyBlankMailer.blank_email.body } }' Calculating ------------------------------------- load 4.466M memsize ( 1.205M retained) 29.202k objects ( 11.943k retained) 50.000 strings ( 50.000 retained) ``` **After:** ``` $ bin/rails r 'Benchmark.memory { |x| x.report("load"){ MyBlankMailer.blank_email.body } }' Calculating ------------------------------------- load 4.462M memsize ( 1.205M retained) 29.141k objects ( 11.940k retained) 50.000 strings ( 50.000 retained) ``` Co-authored-by: Christopher Louvet <[email protected]>
1 parent 0b1b512 commit 763941e

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

actiontext/lib/action_text/engine.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,6 @@ def to_trix_content_attachment_partial_path
5959
end
6060

6161
initializer "action_text.renderer" do
62-
ActiveSupport.on_load(:action_controller_base) do
63-
ActiveSupport.on_load(:action_text_content) do
64-
self.default_renderer = Class.new(ActionController::Base).renderer
65-
end
66-
end
67-
6862
%i[action_controller_base action_mailer].each do |base|
6963
ActiveSupport.on_load(base) do
7064
around_action do |controller, action|

actiontext/lib/action_text/rendering.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ module Rendering # :nodoc:
88
extend ActiveSupport::Concern
99

1010
included do
11-
cattr_accessor :default_renderer, instance_accessor: false
1211
thread_cattr_accessor :renderer, instance_accessor: false
1312
delegate :render, to: :class
1413
end
1514

1615
class_methods do
16+
def action_controller_renderer
17+
@action_controller_renderer ||= Class.new(ActionController::Base).renderer
18+
end
19+
1720
def with_renderer(renderer)
1821
previous_renderer = self.renderer
1922
self.renderer = renderer
@@ -23,7 +26,7 @@ def with_renderer(renderer)
2326
end
2427

2528
def render(*args, &block)
26-
(renderer || default_renderer).render_to_string(*args, &block)
29+
(renderer || action_controller_renderer).render_to_string(*args, &block)
2730
end
2831
end
2932
end

0 commit comments

Comments
 (0)