Skip to content

Commit f9c886f

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 6a35673 commit f9c886f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

docs/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ nav_order: 5
1010

1111
## main
1212

13+
* Fix setting custom `preview_paths`.
14+
15+
*Thomas von Deyen*
16+
1317
* Improve handling of malformed component edge case when mocking components in tests.
1418

1519
*Martin Meyerhoff*, *Joel Hawksley*

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)