Skip to content

Commit

Permalink
Don't duplicate stories_path in autoload_paths (#143)
Browse files Browse the repository at this point in the history
Closes #130
  • Loading branch information
jonspalmer authored Dec 10, 2022
1 parent 107f476 commit a6ea6c0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/view_component/storybook/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Engine < Rails::Engine
options.stories_route ||= "/rails/stories"

if options.show_stories
options.stories_path ||= defined?(Rails.root) ? Rails.root.join("test/components/stories") : nil
options.stories_path ||= defined?(Rails.root) ? Rails.root.join("test/components/stories").to_s : nil
end

options.stories_title_generator ||= ViewComponent::Storybook.stories_title_generator
Expand All @@ -27,7 +27,11 @@ class Engine < Rails::Engine
initializer "view_component.set_autoload_paths" do |app|
options = app.config.view_component_storybook

ActiveSupport::Dependencies.autoload_paths << options.stories_path if options.show_stories && options.stories_path
if options.show_stories &&
options.stories_path &&
ActiveSupport::Dependencies.autoload_paths.exclude?(options.stories_path)
ActiveSupport::Dependencies.autoload_paths << options.stories_path
end
end

config.after_initialize do |app|
Expand Down

0 comments on commit a6ea6c0

Please sign in to comment.