Skip to content

Commit 8be8086

Browse files
committed
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. Fixes #365
1 parent e85b23b commit 8be8086

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/view_component/engine.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ class Engine < Rails::Engine # :nodoc:
7676
end
7777
# :nocov:
7878

79-
initializer "view_component.set_autoload_paths" do |app|
79+
initializer "view_component.set_autoload_paths", before: :set_autoload_paths do |app|
8080
options = app.config.view_component
8181

8282
if options.show_previews && !options.preview_paths.empty?
83-
paths_to_add = options.preview_paths - ActiveSupport::Dependencies.autoload_paths
84-
ActiveSupport::Dependencies.autoload_paths.concat(paths_to_add) if paths_to_add.any?
83+
paths_to_add = options.preview_paths - app.config.autoload_paths
84+
app.config.autoload_paths.concat(paths_to_add) if paths_to_add.any?
8585
end
8686
end
8787

0 commit comments

Comments
 (0)