From d260f8a1aabccee90cd5d65cb4502baebf01459e Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Mon, 16 Dec 2024 16:03:00 +0100 Subject: [PATCH] Fix setting custom preview_paths 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: https://github.com/ViewComponent/view_component/issues/365 --- lib/lookbook/engine.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/lookbook/engine.rb b/lib/lookbook/engine.rb index 354fe4ce..e0f5b374 100644 --- a/lib/lookbook/engine.rb +++ b/lib/lookbook/engine.rb @@ -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