lookbook-hq / lookbook

A UI development environment for Ruby on Rails apps ✨
https://lookbook.build
MIT License
889 stars 91 forks source link

Lookbook overrides ViewComponent `show_previews` config depending on load order #559

Closed ariel-codes closed 8 months ago

ariel-codes commented 10 months ago

Describe the bug

If Lookbook is before ViewComponent in the Gemfile, Lookbook overrides config.view_component.show_previews to true.

To Reproduce

Repo

https://github.com/ariel-codes/vc_preview_false

Steps to reproduce the behavior

In a Rails app generated with rails new --minimal

  1. Add this to Gemfile
    gem "lookbook"
    gem "view_component"
  2. Add this to config/application.rb
    config.view_component.show_previews = false
  3. Start bin/rails s and navigate to http://localhost:3000/rails/view_components/

Expected behavior

Navigation should result in a 404, but instead shows ViewComponent previews.

Version numbers

Please complete the following information:

ariel-codes commented 10 months ago

Maybe this isn't a bug per se – but there should be a warning on the docs since this could make VC previews available in cases that aren't desirable, such as in production.

allmarkedup commented 8 months ago

Hey @ariel-codes, this is intentional as Lookbook requires ViewComponent previews to be available in order to render some previews correctly.

However you are totally correct - there should be a warning in the docs about this. I'll add one in when I get a chance.

I would generally recommend only loading the Lookbook gem in development if you are not using it in production:

group :development do
  gem "lookbook"
end

But regardless as it is silently overriding the ViewComponent config option this should be noted somewhere. Thanks for the suggestion :)

allmarkedup commented 8 months ago

@ariel-codes I've just added a note about this behaviour to the docs so I'm going to go ahead and close this issue now. Thanks again for bringing it to my attention!