Skip to content

Lazy load ActionText helpers #719

@jdufresne

Description

@jdufresne

My application doesn't use ActionText.

Either way, Rails bootstrap_form loads it at:

# NOTE: The rich_text_area and rich_text_area_tag helpers are defined in a file
# with a different name and not in the usual autoload-reachable way.
# The following line is definitely need to make `bootstrap_form` work.
# rubocop:disable Lint/SuppressedException
begin
require "#{Gem::Specification.find_by_name('actiontext').gem_dir}/app/helpers/action_text/tag_helper"
rescue Gem::MissingSpecError
end
# rubocop:enable Lint/SuppressedException

This require statement creates the ActionText module which "tricks" other gems into loading their ActionText support. These gems may do something like:

if defined?(ActionText)
  # Load ActionText support ...
end

This can result in a confusing error message later on when this loaded support eventually fails.

One example of this is RailsAdmin:

https://github.com/railsadminteam/rails_admin/blob/13c90fdd95c3755035b44264dc61e4b65c09ff12/app/assets/javascripts/rails_admin/application.js.erb#L27-L30

I'm wondering if bootstrap_form could somehow use lazy loading to prevent creating the global ActionText module until necessary. If possible, this would improve compatibility between these gems when ActionText is not used.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions