Skip to content

Commit

Permalink
Fix setting custom preview_paths
Browse files Browse the repository at this point in the history
Setting `preview_paths` to anything else than `test/components/previews`
is broken, because we mutate `ActiveSupport::Dependencies.autoload_paths`.

From the Rails guides:

> Please do not mutate ActiveSupport::Dependencies.autoload_paths;
> the public interface to change autoload paths is config.autoload_paths.

Refs: ViewComponent/view_component#365
  • Loading branch information
tvdeyen committed Dec 16, 2024
1 parent 234467d commit d260f8a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/lookbook/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class Engine < Rails::Engine
)
end

initializer "lookbook.set_autoload_paths" do
initializer "lookbook.set_autoload_paths", before: :set_autoload_paths do |app|
if opts.autoload_previews && opts.preview_paths.any?
paths_to_add = opts.preview_paths - ActiveSupport::Dependencies.autoload_paths
paths_to_add = opts.preview_paths - app.config.autoload_paths
filtered_paths = paths_to_add.filter { |p| !Engine.component_paths.include?(p) }
ActiveSupport::Dependencies.autoload_paths.concat(filtered_paths) if filtered_paths.any?
app.config.autoload_paths.concat(filtered_paths) if filtered_paths.any?
end
end

Expand Down

0 comments on commit d260f8a

Please sign in to comment.